{"id":6530,"date":"2024-08-05T15:01:01","date_gmt":"2024-08-05T07:01:01","guid":{"rendered":""},"modified":"2024-08-05T15:01:01","modified_gmt":"2024-08-05T07:01:01","slug":"js\u8de8\u57df\u7684\u51e0\u79cd\u65b9\u6cd5_js\u8de8\u57df\u83b7\u53d6\u6570\u636e\u7684\u65b9\u5f0f","status":"publish","type":"post","link":"https:\/\/mushiming.com\/6530.html","title":{"rendered":"js\u8de8\u57df\u7684\u51e0\u79cd\u65b9\u6cd5_js\u8de8\u57df\u83b7\u53d6\u6570\u636e\u7684\u65b9\u5f0f"},"content":{"rendered":"
\u63d0\u8d77\u8de8\u57df\uff0c\u6211\u4eec\u8981\u5148\u4e86\u89e3\u4e00\u4e0b\u540c\u6e90\u653f\u7b56\uff0c\u9700\u8981\u660e\u786e\u4e00\u70b9\u7684\u662f\uff0c\u540c\u6e90\u653f\u7b56\u662f\u9488\u5bf9\u4e8e\u6d4f\u89c8\u5668\u7684\uff0c\u4e0d\u662f\u9488\u5bf9JS<\/p>\n
\n\u540c\u6e90\u7b56\u7565\u9650\u5236\u4ece\u4e00\u4e2a\u6e90\u52a0\u8f7d\u7684\u6587\u6863\u6216\u811a\u672c\u5982\u4f55\u4e0e\u6765\u81ea\u53e6\u4e00\u4e2a\u6e90\u7684\u8d44\u6e90\u8fdb\u884c\u4ea4\u4e92\u3002\u8fd9\u662f\u4e00\u4e2a\u7528\u4e8e\u9694\u79bb\u6f5c\u5728\u6076\u610f\u6587\u4ef6\u7684\u5173\u952e\u7684\u5b89\u5168\u673a\u5236\u3002--MDN<\/p>\n<\/blockquote>\n
\u901a\u4fd7\u6765\u8bb2\u5c31\u662f\u6d4f\u89c8\u5668\u51fa\u4e8e\u5b89\u5168\u65b9\u9762\u7684\u8003\u8651\uff0c\u53ea\u5141\u8bb8\u4e0e\u672c\u57df\u4e0b\u7684\u63a5\u53e3\u4ea4\u4e92\u3002\u4e0d\u540c\u6e90\u7684\u5ba2\u6237\u7aef\u811a\u672c\u5728\u6ca1\u6709\u660e\u786e\u6388\u6743\u7684\u60c5\u51b5\u4e0b\uff0c\u4e0d\u80fd\u8bfb\u5199\u5bf9\u65b9\u7684\u8d44\u6e90\u3002\u90a3\u4e48\u600e\u6837\u662f\u540c\u6e90\u5462\uff1f
\u540c\u6e90\u6307\u7684\u662f\uff1a<\/p>\n\n
- \u540c\u534f\u8bae\uff1a\u5982\u90fd\u662fhttp\u6216\u8005https<\/li>\n
- \u540c\u57df\u540d\uff1a\u5982\u90fd\u662f
http:\/\/jirengu.com\/a<\/code>\u548c
http:\/\/jirengu.com\/b<\/code><\/li>\n
- \u540c\u7aef\u53e3\uff1a\u5982\u90fd\u662f80\u7aef\u53e3<\/li>\n<\/ul>\n
\u4ee5
https:\/\/plainnany.github.io<\/code>\u4e3a\u4f8b
\u8be5url\u7684\u534f\u8bae\u4e3ahttps\uff0c\u57df\u540d\u662fplainnany.github.io\uff0c\u7aef\u53e3\u4e3a443\uff0c\u9ed8\u8ba4\u7aef\u53e3\u53ef\u4ee5\u7701\u7565\u3002<\/p>\n\n
https:\/\/plainnany.github.io\/archives<\/code> \u540c\u6e90\uff0c\u534f\u8bae\u3001\u57df\u540d\u3001\u7aef\u53e3\u90fd\u76f8\u540c<\/li>\n
http:\/\/plainnany.github.io<\/code> \u4e0d\u540c\u6e90\uff0c\u534f\u8bae\u4e0d\u540c<\/li>\n
https:\/\/other.github.io<\/code> \u4e0d\u540c\u6e90\uff0c\u57df\u540d\u4e0d\u540c<\/li>\n
https:\/\/plainnany.github.io:442<\/code> \u4e0d\u540c\u6e90\uff0c\u7aef\u53e3\u4e0d\u540c<\/li>\n<\/ul>\n
\u90a3\u4e48\u95ee\u9898\u6765\u4e86\uff0c\u6211\u5c31\u662f\u60f3\u8bbf\u95ee\u5176\u4ed6\u57df\uff08\u975e\u540c\u6e90\uff09\u7684\u8d44\u6e90----\u5373\u8de8\u57df\uff0c\u8be5\u600e\u4e48\u505a\u5462\uff1f<\/p>\n
2. \u5982\u4f55\u8de8\u57df<\/h3>\n
\u5e38\u7528\u7684\u8de8\u57df\u65b9\u6cd5\u6709JSONP\uff0cCORS\uff0cpostmessage\u7b49\uff0c<\/p>\n
2.1 JSONP<\/h3>\n
JSONP\u662fJSON with padding\uff08\u586b\u5145\u5f0fJSON\u6216\u53c2\u6570\u662fJSON\uff09\u7684\u7b80\u5199\uff0c\u662f\u5e94\u7528JSON\u7684\u4e00\u79cd\u65b0\u65b9\u6cd5\uff0cJSONP\u770b\u8d77\u6765\u548cJSON\u5dee\u4e0d\u591a\uff0c\u53ea\u4e0d\u8fc7\u662f\u88ab\u5305\u542b\u5728\u51fd\u6570\u8c03\u7528\u7684JSON\uff0c\u50cf\u8fd9\u6837\uff1acallback({name: 'nany'})\u3002<\/p>\n
2.1.1 JSONP\u8de8\u57df\u539f\u7406<\/h4>\n
\u6211\u4eec\u77e5\u9053html\u4e2dscript\u901a\u8fc7src\u5c5e\u6027\u53ef\u4ee5\u5f15\u5165\u5176\u4ed6\u57df\u4e0b\u7684js\uff0c\u6bd4\u5982\u5f15\u5165\u7ebf\u4e0a\u7684jquery\u5e93\u3002\u4e5f\u53ef\u4ee5\u5f15\u5165\u975ejs\u7684\u6587\u4ef6\uff0c\u5229\u7528\u8fd9\u4e2a\u7279\u6027\uff0c\u53ef\u5b9e\u73b0\u8de8\u57df\u8bbf\u95ee\u63a5\u53e3\u3002\u8be5\u65b9\u6cd5\u9700\u8981\u540e\u7aef\u652f\u6301\u3002<\/p>\n
\n
- \u5b9a\u4e49\u6570\u636e\u5904\u7406\u51fd\u6570_fun<\/li>\n
- \u521b\u5efascript\u6807\u7b7e\uff0csrc\u7684\u5730\u5740\u6267\u884c\u540e\u7aef\u63a5\u53e3\uff0c\u6700\u540e\u52a0\u4e2a\u53c2\u6570callback=_fun<\/li>\n
- \u670d\u52a1\u7aef\u5728\u6536\u5230\u8bf7\u6c42\u540e\uff0c\u89e3\u6790\u53c2\u6570\uff0c\u8ba1\u7b97\u8fd4\u8fd8\u6570\u636e\uff0c\u8f93\u51fa fun(data) \u5b57\u7b26\u4e32\u3002<\/li>\n
- fun(data)\u4f1a\u653e\u5230script\u6807\u7b7e\u505a\u4e3ajs\u6267\u884c\u3002\u6b64\u65f6\u4f1a\u8c03\u7528fun\u51fd\u6570\uff0c\u5c06data\u505a\u4e3a\u53c2\u6570\u3002<\/li>\n<\/ol>\n
2.1.2 \u5b9e\u73b0\u65b9\u5f0f<\/h4>\n
\u4ee5\u4e0b\u9762\u4f8b\u5b50\u4e3a\u4f8b\uff0c\u6211\u4eec\u7528nodejs\u76d1\u542c\u540e\u7aef\u6587\u4ef6\uff0c\u540c\u65f6\u5728\u672c\u5730\u6253\u5f00\u524d\u7aef\u9875\u9762\u6765\u6a21\u62df\u8de8\u57df\u3002
\u524d\u7aef\u9875\u9762<\/p>\n<!DOCTYPE html>\n<html>\n<head>\n<meta charset=\"utf-8\">\n<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge,chrome=1\">\n <title>index.html<\/title>\n<\/head>\n<body>\n <script>\n function jsonpCallback(data) { \/\/ \u76f8\u5bf9\u540e\u7aef\u63a5\u53e3\u6240\u9700\u8981\u7684\u5904\u7406\u51fd\u6570\n alert('\u7528JSONP\u8de8\u57df\uff0c\u83b7\u5f97\u6570\u636e:' + data.x);\n }\n <\/script>\n <script src=\"http:\/\/127.0.0.1:3000?callback=jsonpCallback\"><\/script> \/\/ \u53d1\u9001\u8bf7\u6c42\n<\/body>\n<\/html>\n<\/code><\/pre>\n
\u540e\u7aef\u9875\u9762<\/p>\n
const url = require('url'); require('http').createServer((req, res) => { const data = { x: 10 } const callback = url.parse(req.url, true).query.callback \/\/ res.writeHead(200) res.end(`${callback}(${JSON.stringify(data)})`) \/\/ \u670d\u52a1\u5668\u6536\u5230\u8bf7\u6c42\u540e\uff0c\u89e3\u6790\u53c2\u6570\uff0c \/\/ \u5c06callback(data)\u4ee5\u5b57\u7b26\u4e32\u7684\u5f62\u5f0f\u8fd4\u8fd8\u6570\u636e\uff0c\u524d\u7aef\u9875\u9762\u4f1a\u5c06callback(data)\u4f5c\u4e3ajs\u6267\u884c \/\/ \u8c03\u7528jsonpCallback(data)\u51fd\u6570\u3002 }).listen(3000, '127.0.0.1'); console.log('\u542f\u52a8\u670d\u52a1\uff0c\u76d1\u542c 127.0.0.1:3000'); <\/code><\/pre>\n
<\/p>\n
image<\/p>\n
JSONP\u8de8\u57df\u4e0d\u50cf\u4e0b\u9762\u7684CORS\u8de8\u57df\u90a3\u6837\u53d7\u540c\u6e90\u653f\u7b56\u7684\u5f71\u54cd\uff0c\u800c\u4e14\u517c\u5bb9\u6027\u4e5f\u6bd4\u8f83\u597d\uff0c\u4f46JSONP\u8de8\u57df\u4e5f\u6709\u5176\u7f3a\u70b9\uff0c\u4e3b\u8981\u8868\u73b0\u5728\uff1a<\/p>\n
\n
- \u5b83\u652f\u6301 GET \u8bf7\u6c42\u800c\u4e0d\u652f\u6301 POST \u7b49\u5176\u5b83\u7c7b\u884c\u7684 HTTP \u8bf7\u6c42\u3002<\/li>\n
- \u5b83\u53ea\u652f\u6301\u8de8\u57df HTTP \u8bf7\u6c42\u8fd9\u79cd\u60c5\u51b5\uff0c\u4e0d\u80fd\u89e3\u51b3\u4e0d\u540c\u57df\u7684\u4e24\u4e2a\u9875\u9762\u6216 iframe \u4e4b\u95f4\u8fdb\u884c\u6570\u636e\u901a\u4fe1\u7684\u95ee\u9898<\/li>\n
- JSONP\u4ece\u5176\u4ed6\u57df\u4e2d\u52a0\u8f7d\u4ee3\u7801\u6267\u884c\uff0c\u5982\u679c\u8be5\u57df\u4e0d\u5b89\u5168\u5e76\u4e14\u5939\u5e26\u4e00\u4e9b\u6076\u610f\u4ee3\u7801\uff0c\u4f1a\u5b58\u5728\u5b89\u5168\u9690\u60a3<\/li>\n
- \u8981\u786e\u5b9aJSONP\u8bf7\u6c42\u662f\u5426\u5931\u8d25\u5e76\u4e0d\u5bb9\u6613<\/li>\n<\/ol>\n
2.2 CORS<\/h3>\n
2.2.1 CORS\u539f\u7406<\/h4>\n
CORS \u5168\u79f0\u662f\u8de8\u57df\u8d44\u6e90\u5171\u4eab\uff08Cross-Origin Resource Sharing\uff09\uff0c\u662f\u4e00\u79cd ajax \u8de8\u57df\u8bf7\u6c42\u8d44\u6e90\u7684\u65b9\u5f0f\uff0c\u652f\u6301\u73b0\u4ee3\u6d4f\u89c8\u5668\uff0cIE\u652f\u630110\u4ee5\u4e0a\u3002 \u5b9e\u73b0\u65b9\u5f0f\u5f88\u7b80\u5355\uff0c\u5f53\u4f60\u4f7f\u7528 XMLHttpRequest \u53d1\u9001\u8bf7\u6c42\u65f6\uff0c\u6d4f\u89c8\u5668\u53d1\u73b0\u8be5\u8bf7\u6c42\u4e0d\u7b26\u5408\u540c\u6e90\u7b56\u7565\uff0c\u4f1a\u7ed9\u8be5\u8bf7\u6c42\u52a0\u4e00\u4e2a\u8bf7\u6c42\u5934\uff1aOrigin\uff0c\u540e\u53f0\u8fdb\u884c\u4e00\u7cfb\u5217\u5904\u7406\uff0c\u5982\u679c\u786e\u5b9a\u63a5\u53d7\u8bf7\u6c42\u5219\u5728\u8fd4\u56de\u7ed3\u679c\u4e2d\u52a0\u5165\u4e00\u4e2a\u54cd\u5e94\u5934\uff1aAccess-Control-Allow-Origin; \u6d4f\u89c8\u5668\u5224\u65ad\u8be5\u76f8\u5e94\u5934\u4e2d\u662f\u5426\u5305\u542b Origin \u7684\u503c\uff0c\u5982\u679c\u6709\u5219\u6d4f\u89c8\u5668\u4f1a\u5904\u7406\u54cd\u5e94\uff0c\u6211\u4eec\u5c31\u53ef\u4ee5\u62ff\u5230\u54cd\u5e94\u6570\u636e\uff0c\u5982\u679c\u4e0d\u5305\u542b\u6d4f\u89c8\u5668\u76f4\u63a5\u9a73\u56de\uff0c\u8fd9\u65f6\u6211\u4eec\u65e0\u6cd5\u62ff\u5230\u54cd\u5e94\u6570\u636e\u3002\u6240\u4ee5 CORS \u7684\u8868\u8c61\u662f\u8ba9\u4f60\u89c9\u5f97\u5b83\u4e0e\u540c\u6e90\u7684 ajax \u8bf7\u6c42\u6ca1\u5565\u533a\u522b\uff0c\u4ee3\u7801\u5b8c\u5168\u4e00\u6837\u3002
CORS\u53c8\u5206\u7b80\u5355\u8bf7\u6c42\u548c\u975e\u7b80\u5355\u8bf7\u6c42
\u7b80\u5355\u8bf7\u6c42\uff1a
\u6bd4\u5982\u53d1\u9001\u4e86\u4e00\u4e2aorigin\u7684\u5934\u90e8
Origin : http: \/\/www.nczonline.net
\u5982\u679c\u670d\u52a1\u5668\u8ba4\u4e3a\u8fd9\u4e2a\u8bf7\u6c42\u53ef\u4ee5\u63a5\u53d7\uff0c\u5c31\u5728Access-Control-Allow-Origin\u5934\u90e8\u56de\u53d1\u76f8\u540c\u7684\u6e90\u4fe1\u606f
Access-Control-Allow-Origin : http: \/\/www.nczonline.net
\u6bd4\u5982\u53d1\u9001\u4e86\u4e00\u4e2aorigin\u7684\u5934\u90e8Origin : http: \/\/www.nczonline.net<\/code>
\u5982\u679c\u670d\u52a1\u5668\u8ba4\u4e3a\u8fd9\u4e2a\u8bf7\u6c42\u53ef\u4ee5\u63a5\u53d7\uff0c\u5c31\u5728Access-Control-Allow-Origin\u5934\u90e8\u56de\u53d1\u76f8\u540c\u7684\u6e90\u4fe1\u606fAccess-Control-Allow-Origin : http: \/\/www.nczonline.net<\/code>
\u975e\u7b80\u5355\u8bf7\u6c42\uff1a
\u975e\u7b80\u5355\u8bf7\u6c42\u662f\u90a3\u79cd\u5bf9\u670d\u52a1\u5668\u6709\u7279\u6b8a\u8981\u6c42\u7684\u8bf7\u6c42\uff0c\u6bd4\u5982\u8bf7\u6c42\u65b9\u6cd5\u662fPUT\u6216DELETE\uff0c\u6216\u8005Content-Type\u5b57\u6bb5\u7684\u7c7b\u578b\u662fapplication\/json\u3002
\u975e\u7b80\u5355\u8bf7\u6c42\u7684CORS\u8bf7\u6c42\uff0c\u4f1a\u5728\u6b63\u5f0f\u901a\u4fe1\u4e4b\u524d\uff0c\u589e\u52a0\u4e00\u6b21HTTP\u67e5\u8be2\u8bf7\u6c42\uff0c\u79f0\u4e3a\u201c\u9884\u68c0\u201d\u8bf7\u6c42\uff08preflight\uff09\u3002
\u6d4f\u89c8\u5668\u5148\u8be2\u95ee\u670d\u52a1\u5668\uff0c\u5f53\u524d\u7f51\u9875\u6240\u5728\u7684\u57df\u540d\u662f\u5426\u5728\u670d\u52a1\u5668\u7684\u8bb8\u53ef\u540d\u5355\u4e4b\u4e2d\uff0c\u4ee5\u53ca\u53ef\u4ee5\u4f7f\u7528\u54ea\u4e9bHTTP\u52a8\u8bcd\u548c\u5934\u4fe1\u606f\u5b57\u6bb5\u3002\u53ea\u6709\u5f97\u5230\u80af\u5b9a\u7b54\u590d\uff0c\u6d4f\u89c8\u5668\u624d\u4f1a\u53d1\u51fa\u6b63\u5f0f\u7684XMLHttpRequest\u8bf7\u6c42\uff0c\u5426\u5219\u5c31\u62a5\u9519\u3002<\/p>\n\u8be6\u89c1\u962e\u4e00\u5cf0 CORS\u901a\u4fe1<\/p>\n
2.2.2 \u5b9e\u73b0\u65b9\u5f0f<\/h4>\n
\u6211\u4eec\u7528nodejs\u76d1\u542c\u540e\u7aef\u6587\u4ef6\uff0c\u7528http-server\u6253\u5f00\u524d\u7aef\u6587\u4ef6\u6765\u6a21\u62df\u8de8\u57df
\u524d\u7aef<\/p>\n<!doctype>\n<html lang=\"en\">\n<head>\n <meta charset=\"UTF-8\">\n <title>index.html<\/title>\n<\/head>\n<body>\n <script>\n const xhr = new XMLHttpRequest();\n xhr.open('GET', 'http:\/\/127.0.0.1:3000', true);\n xhr.onreadystatechange = function() {\n if(xhr.readyState === 4 && xhr.status === 200) {\n alert(xhr.responseText);\n }\n }\n xhr.send(null);\n <\/script>\n<\/body>\n<\/html>\n<\/code><\/pre>\n
\u540e\u7aef\u4ee3\u7801<\/p>\n
const url = require('url') require('http').createServer((req, res) => { res.writeHead(200, { 'Access-Control-Allow-Origin': 'http:\/\/localhost:8080' }) res.end('\u7528CORS\u8de8\u57df\u6210\u529f') }).listen(3000, '127.0.0.1') console.log('\u542f\u52a8\u670d\u52a1\uff0c\u76d1\u542c 127.0.0.1:3000') <\/code><\/pre>\n
<\/p>\n
image<\/p>\n
<\/p>\n
CORS \u7684\u4f18\u7f3a\u70b9\uff1a<\/p>\n
\n
- \u4f7f\u7528\u7b80\u5355\u65b9\u4fbf\uff0c\u66f4\u4e3a\u5b89\u5168<\/li>\n
- \u652f\u6301 POST \u8bf7\u6c42\u65b9\u5f0f<\/li>\n
- CORS \u662f\u4e00\u79cd\u65b0\u578b\u7684\u8de8\u57df\u95ee\u9898\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u5b58\u5728\u517c\u5bb9\u95ee\u9898\uff0c\u4ec5\u652f\u6301 IE 10 \u4ee5\u4e0a<\/li>\n<\/ol>\n
2.3 \u964d\u57df<\/h3>\n
2.3.1 \u964d\u57df\u539f\u7406<\/h4>\n
\u5f53\u4e24\u4e2a\u9875\u9762\u4e0d\u540c\u57df\uff0c\u4f46\u662f\u5b83\u4eec\u7684\u7236\u57df\u4e4b\u4e0a\u90fd\u76f8\u540c(\u7aef\u53e3)\uff0c\u90a3\u4e48\u53ef\u4ee5\u4f7f\u7528\u964d\u57df\u7684\u65b9\u6cd5\u6765\u5b9e\u73b0\u8de8\u57df\u3002
\u5bf9\u4e8e\u4e3b\u57df\u76f8\u540c\u800c\u5b50\u57df\u4e0d\u540c\u7684\u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6e document.domain \u7684\u529e\u6cd5\u6765\u89e3\u51b3\uff0c
\u5177\u4f53\u505a\u6cd5\u662f\u53ef\u4ee5\u5728url\u4e3aa.nany.com:8080\u4e0b\u7684a.html \u548cb.nany.com:8080\u4e0b\u7684b.html \u4e24\u4e2a\u6587\u4ef6\u5206\u522b\u52a0\u4e0a document.domain = \"nany.com\"\uff1b\u7136\u540e\u901a\u8fc7 a.html \u6587\u4ef6\u521b\u5efa\u4e00\u4e2a iframe\uff0c\u53bb\u63a7\u5236 iframe \u7684 window\uff0c\u4ece\u800c\u8fdb\u884c\u4ea4\u4e92\uff0c\u5f53\u7136\u8fd9\u79cd\u65b9\u6cd5\u53ea\u80fd\u89e3\u51b3\u4e3b\u57df\u76f8\u540c\u800c\u4e8c\u7ea7\u57df\u540d\u4e0d\u540c\u7684\u60c5\u51b5\u3002<\/p>\n\u5b9e\u73b0\u65b9\u5f0f<\/h4>\n
\u9996\u5148\u914d\u7f6e\u7cfb\u7edf<\/strong>\u7684hosts\u6587\u4ef6\uff0c\u5982\u679c\u4f60\u7684git bash\u5b89\u88c5\u7684\u4e0d\u662f\u5728c\u76d8\uff0c\u5343\u4e07\u4e0d\u8981\u76f4\u63a5\u53bb\u627e \/etc\u4e0b\u7684hosts\u6587\u4ef6\u3002
\u5982\u6211\u7684\u662f\u5728<\/p>\n<\/p>\n
\u7136\u540e\u6dfb\u52a0<\/p>\n
<\/p>\n
<\/p>\n
a.html \u4ee3\u7801<\/p>\n
<html>\n<style>\n .ct{\n width: 910px;\n margin: auto;\n }\n .main{\n float: left;\n width: 450px;\n height: 300px;\n border: 1px solid #ccc;\n }\n .main input{\n margin: 20px;\n width: 200px;\n }\n .iframe{\n float: right;\n }\n iframe{\n width: 450px;\n height: 300px;\n border: 1px dashed #ccc;\n }\n<\/style>\n\n<div class=\"ct\">\n <h1>\u4f7f\u7528\u964d\u57df\u5b9e\u73b0\u8de8\u57df<\/h1>\n <div class=\"main\">\n <input type=\"text\" placeholder=\"http:\/\/a.nany.com:8080\/a.html\">\n <\/div>\n\n <iframe src=\"http:\/\/b.nany.com:8080\/b.html\" frameborder=\"0\" ><\/iframe>\n\n<\/div>\n\n\n<script>\n\/\/URL: http:\/\/a.jrg.com:8080\/a.html\ndocument.querySelector('.main input').addEventListener('input', function(){\n console.log(this.value);\n window.frames[0].document.querySelector('input').value = this.value;\n})\ndocument.domain = 'nany.com'\n<\/script>\n<\/html>\n<\/code><\/pre>\n
b.html \u4ee3\u7801<\/p>\n
<html>\n<style>\n html,body{\n margin: 0;\n }\n input{\n margin: 20px;\n width: 200px;\n }\n<\/style>\n\n <input id=\"input\" type=\"text\" placeholder=\"http:\/\/b.nany.com:8080\/b.html\">\n<script>\n\/\/ URL: http:\/\/b.jrg.com:8080\/b.html\n \ndocument.querySelector('#input').addEventListener('input', function(){\n window.parent.document.querySelector('input').value = this.value;\n})\ndocument.domain = 'nany.com';\n<\/script>\n<\/html>\n<\/code><\/pre>\n
\u7528http-server\u76d1\u542c\uff0c\u5728\u6d4f\u89c8\u5668\u8f93\u5165http:\/\/b.nany.com:8080\/a.html \u6216\u8005http:\/\/a.nany.com:8080\/a.html \u5373\u53ef\u5b9e\u73b0\u8de8\u57df<\/p>\n
<\/p>\n
\u53c2\u8003\uff1a<\/h4>\n
\n
- \u5173\u4e8e\u8de8\u57df\uff0c\u4f60\u60f3\u77e5\u9053\u7684\u5168\u5728\u8fd9\u91cc<\/li>\n
- \u962e\u4e00\u5cf0 CORS\u901a\u4fe1<\/li>\n<\/ul>\n
<\/p>\n","protected":false},"excerpt":{"rendered":"js\u8de8\u57df\u7684\u51e0\u79cd\u65b9\u6cd5_js\u8de8\u57df\u83b7\u53d6\u6570\u636e\u7684\u65b9\u5f0f\u4f5c\u8005\uff1aplainnany\u94fe\u63a5\uff1ahttps:\/\/www.jianshu.com\/p\/b6c40d8c9ad4\u4f86\u6e90\uff1a\u7b80\u4e661.\u4ec0\u4e48\u662f\u8de8...","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"_links":{"self":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/6530"}],"collection":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/comments?post=6530"}],"version-history":[{"count":0,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/posts\/6530\/revisions"}],"wp:attachment":[{"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/media?parent=6530"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/categories?post=6530"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mushiming.com\/wp-json\/wp\/v2\/tags?post=6530"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}