{"id":5505,"date":"2016-11-11T09:38:09","date_gmt":"2016-11-11T01:38:09","guid":{"rendered":"https:\/\/sdeno.com\/?p=5505"},"modified":"2016-11-11T11:42:07","modified_gmt":"2016-11-11T03:42:07","slug":"%e8%af%a6%e8%a7%a35%e7%a7%8d%e8%b7%a8%e5%9f%9f%e6%96%b9%e5%bc%8f%e5%8f%8a%e5%85%b6%e5%8e%9f%e7%90%86%e6%8e%a8%e8%8d%90","status":"publish","type":"post","link":"https:\/\/sdeno.com\/?p=5505","title":{"rendered":"\u8be6\u89e35\u79cd\u8de8\u57df\u65b9\u5f0f\u53ca\u5176\u539f\u7406(\u63a8\u8350)"},"content":{"rendered":"<table style=\"color: #3e3e3e;\" border=\"1\">\n<thead>\n<tr>\n<th>URL<\/th>\n<th align=\"center\">\u7ed3\u679c<\/th>\n<th align=\"right\">\u539f\u56e0<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td><a style=\"color: #448aff;\">http:\/\/store.company.com\/dir2\/other.html<\/a><\/td>\n<td align=\"center\">Success<\/td>\n<td align=\"right\"><\/td>\n<\/tr>\n<tr>\n<td><a style=\"color: #448aff;\">http:\/\/store.company.com\/dir\/inner\/another.html<\/a><\/td>\n<td align=\"center\">Success<\/td>\n<td align=\"right\"><\/td>\n<\/tr>\n<tr>\n<td><a style=\"color: #448aff;\">https:\/\/store.company.com\/secure.html<\/a><\/td>\n<td align=\"center\">\u5c5e\u4e8e\u8de8\u57dfFailure<\/td>\n<td align=\"right\">\u534f\u8bae\u4e0d\u540c<\/td>\n<\/tr>\n<tr>\n<td><a style=\"color: #448aff;\">http:\/\/store.company.com:81\/dir\/etc.html<\/a><\/td>\n<td align=\"center\">\u5c5e\u4e8e\u8de8\u57dfFailure<\/td>\n<td align=\"right\">\u7aef\u53e3\u4e0d\u540c<\/td>\n<\/tr>\n<tr>\n<td><a style=\"color: #448aff;\">http:\/\/news.company.com\/dir\/other.html<\/a><\/td>\n<td align=\"center\">\u5c5e\u4e8e\u8de8\u57dfFailure<\/td>\n<td align=\"right\">\u4e3b\u673a\u4e0d<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #ff0000;\">1.jsonp<\/span><\/p>\n<p>\u8fd9\u4e2a\u65b9\u6cd5\u4e5f\u662f\u6700\u5e38\u7528\u7684\u65b9\u6cd5\u6765\u89e3\u51b3\u8de8\u57df\u7684\u95ee\u9898\uff0c\u76f4\u63a5\u4e0a\u6848\u4f8b\uff1a<\/p>\n<p>script\u6807\u7b7e\u662f\u4e0d\u53d7\u540c\u6e90\u7b56\u7565\u5f71\u54cd\u7684\uff0c\u5b83\u53ef\u4ee5\u5f15\u5165\u6765\u81ea\u4efb\u4f55\u5730\u65b9\u7684js\u6587\u4ef6\u3002<br \/>\n\u800cjsonp\u7684\u539f\u7406\u5c31\u662f\uff0c\u5728\u5ba2\u6237\u7aef\u548c\u670d\u52a1\u7aef\u5b9a\u4e49\u4e00\u4e2a\u51fd\u6570\uff0c\u5f53\u5ba2\u6237\u7aef\u53d1\u8d77\u4e00\u4e2a\u8bf7\u6c42\u65f6\uff0c\u670d\u52a1\u7aef\u8fd4\u56de\u4e00\u6bb5javascript\u4ee3\u7801\uff0c\u5176\u4e2d\u8c03\u7528\u4e86\u5728\u5ba2\u6237\u7aef\u5b9a\u4e49\u7684\u51fd\u6570\uff0c\u5e76\u5c06\u76f8\u5e94\u7684\u6570\u636e\u4f5c\u4e3a\u53c2\u6570\u4f20\u5165\u8be5\u51fd\u6570\u3002<\/p>\n<pre>\/\/\u5ba2\u6237\u7aef\u8bbe\u7f6e\r\n&lt;body&gt;\r\n  &lt;button onclick=\"ajax()\"&gt;\u70b9&lt;\/button&gt;\r\n&lt;\/body&gt;\r\n\r\n\r\n&lt;script&gt;\r\n function ajax(){\r\n   var url = \"http:\/\/localhost\/1.php?jsonp_callback=<span style=\"color: #ff0000;\">jsonp_cb<\/span>\";\r\n   var script = document.createElement('script');\r\n   \/\/ \u53d1\u9001\u8bf7\u6c42\r\n   script.src = url;\r\n   document.head.appendChild(script);\r\n }\r\n\r\n function jsonp_cb(data) {\r\n   alert(data);\r\n }\r\n&lt;\/script&gt;\r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p>\u670d\u52a1\u7aef\u83b7\u53d6\u5230jsonp_callback\u4f20\u9012\u7684\u51fd\u6570\u540djsonp_cb\uff0c\u8fd4\u56de\u4e00\u6bb5\u5bf9\u8be5\u51fd\u6570\u8c03\u7528\u7684js\u4ee3\u7801<\/p>\n<pre>\/\/1.php\u670d\u52a1\u5668\u7aef\r\n&lt;?php\r\n  echo'<span style=\"color: #ff0000;\">jsonp_cb<\/span>({\"name\": \"story\"})';\r\n  \/\/\u6216\u8005 echo $_GET['jsonp_callback'].'({\"name\": \"story\"})';\r\n?&gt;<\/pre>\n<p>\u8fd9\u91cc\u63a8\u8350\u4f7f\u7528jquery\u6765\u505a\uff0c\u5b83\u5b9e\u73b0\u4e86\u517c\u5bb9\u53ef\u4ee5\u53c2\u8003\u6848\u4f8b\uff1a\u300a<a href=\"https:\/\/sdeno.com\/?p=3647\" target=\"_blank\">jquery ajax \u8de8\u57df\u5b9e\u4f8b<\/a>\u300b<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #ff0000;\">2.img ping<\/span><\/p>\n<pre>var img=new Image();\r\nimg.src='https:\/\/sdeno.com\/xx.jpg';  \/\/\u8bf7\u6c42\u522b\u7684\u7f51\u7ad9\u7684\u56fe\u7247\uff0c\u5176\u5b9e\u4e5f\u662f\u5b9e\u73b0\u4e86\u8de8\u57df\uff0c\u53ea\u662f\u672c\u5730\u5ba2\u6237\u7aef\u53ea\u80fd\u901a\u8fc7get\u65b9\u5f0f\u6765\u8bf7\u6c42\uff0c\r\nimg.onerror=function(){                   \/\/\u800c\u5ba2\u6237\u7aef\u65e0\u6cd5\u83b7\u53d6\u5230\u670d\u52a1\u5668\u53d1\u6765\u7684\u4fe1\u606f\r\n alert('error');\r\n}\r\nimg.onload=function(){\r\n alert('success');\r\n}<\/pre>\n<p>\u4f7f\u7528\u56fe\u7247ping\u8de8\u57df\u53ea\u80fd\u53d1\u9001get\u8bf7\u6c42\uff0c\u5e76\u4e14\u4e0d\u80fd\u8bbf\u95ee\u54cd\u5e94\u7684\u6587\u672c\uff0c\u53ea\u80fd\u76d1\u542c\u662f\u5426\u54cd\u5e94\u800c\u5df2\uff0c\u53ef\u4ee5\u7528\u6765\u8ffd\u8e2a\u5e7f\u544a\u70b9\u51fb\u3002<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #ff0000;\">\u00a03.window.name<\/span><\/p>\n<p>window\u5bf9\u8c61\u62e5\u6709name\u5c5e\u6027\uff0c\u5b83\u6709\u4e00\u4e2a\u7279\u70b9\uff1a\u76f8\u540c\u534f\u8bae\u4e0b\uff0c\u5728\u4e00\u4e2a\u9875\u9762\u4e2d\uff0c\u4e0d\u968fURL\u7684\u6539\u53d8\u800c\u6539\u53d8<\/p>\n<p>\u4e0d\u7ba1\u4ec0\u4e48\u7c7b\u4f3c\u7684\u6570\u636e\u8d4b\u503c\u5728window.name\u4e0a\u90fd\u662f\u8f6c\u5316\u4e3a\u5b57\u7b26\u4e32<\/p>\n<pre>window.name = function(){}\r\nconsole.log(window.name)\r\n\/\/ \"function(){}\"<\/pre>\n<p>&nbsp;<\/p>\n<p>iframe\u62e5\u6709contentWindow\u5c5e\u6027\uff0c\u662f\u7ed9\u5ba2\u6237\u7aef\u4f7f\u7528\u7684\uff0c\u4e13\u95e8\u7528\u6765\u83b7\u53d6\u670d\u52a1\u5668\u7aef\u90a3\u5934\u8bbe\u7f6e\u7684window.name\u7684\u503c\u3002iframe\u7684src\u7b2c\u4e00\u6b21\u52a0\u8f7d\u6210\u529f\u540e\u5df2\u7ecf\u80fd\u83b7\u53d6\u5230window.name\u4e86\uff0c\u5982\u679c\u662f\u8de8\u57df\uff0c\u8fd8\u8981\u518d\u6b21\u628asrc\u4fee\u6539\u4e3a\u672c\u5730\u5730\u5740\u5c31\u53ef\u4ee5\u5728\u5ba2\u6237\u7aef\u4f7f\u7528iframe.contentWindow.name\u6765\u83b7\u53d6\u8de8\u57df\u5730\u5740\u90a3\u8fb9\u7684window.name\u503c<\/p>\n<pre>\/\/\u5ba2\u6237\u7aef\u8bbe\u7f6e\r\n&lt;script&gt;\r\n var url = \"http:\/\/localhost\/1.php\"; \/\/\u8981\u8de8\u57df\u83b7\u53d6\u6570\u636e\u7684\u7f51\u7ad9\r\n var iframe = document.createElement('iframe');\r\n iframe.src = url; \/\/iframe\u52a0\u8f7d\u5730\u5740\u65f6\uff0c\u9875\u9762\u7684\u53e6\u4e00\u5934\u8bbe\u7f6e\u4e86window.name='\u503c';\r\n document.body.appendChild(iframe)\r\n var state = true;\r\n\r\n iframe.onload = function(){ \/\/\u5f53iframe\u7684\u9875\u9762\u5b8c\u5168\u52a0\u8f7d\u5b8c\u540e\u89e6\u53d1\r\n   if(state === true){\/\/\u8fd9\u91cc\u4f7f\u7528if\u662f\u907f\u514d\u4e86\u65e0\u9650\u662f\u5237\u65b0\uff0c\u56e0\u4e3a\u8981\u4fee\u6539iframe\u7684src\u5730\u5740\u4e3a\u672c\u5730\r\n     iframe.src = ''; \/\/\u518d\u6b21\u4fee\u6539src\uff0c\u8981\u5c5e\u4e8e\u540c\u6e90\u624d\u80fd\u4f7f\u7528iframe.contentWindow.name\u83b7\u53d6\u5230\u8de8\u57df\u7f51\u7ad9\u8bbe\u7f6e\u7684window.name\u503c\r\n     state = false;\r\n   }else if(state === false){\r\n     state = null\r\n     var data = iframe.contentWindow.name;\/\/\u5728\u5ba2\u6237\u7aef\u4f7f\u7528iframe.contentWindow.name\uff0c\u5c31\u80fd\u83b7\u53d6\u5230\u670d\u52a1\u5668\u90a3\u8fb9\u8bbe\u7f6e\u7684window.name\u7684\u503c\uff0c\u8fbe\u5230\u8de8\u57df\u7684\u6548\u679c\r\n     console.log(data)\r\n   }\r\n }\r\n&lt;\/script&gt;<\/pre>\n<p>&nbsp;<\/p>\n<pre>\/\/1.php  \u670d\u52a1\u5668\u7aef\r\n&lt;?php\r\n echo '&lt;script&gt; window.name = \"{\\\"name\\\":\\\"story\\\"}\"&lt;\/script&gt;';\r\n?&gt;<\/pre>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #ff0000;\">\u00a04.postMessage<\/span><\/p>\n<p>postMessage\u5141\u8bb8\u4e0d\u540c\u6e90\u4e4b\u95f4\u7684\u811a\u672c\u8fdb\u884c\u901a\u4fe1\uff0c\u7528\u6cd5<\/p>\n<pre>otherWindow.postMessage(message, targetOrigin);<\/pre>\n<p>otherWindow \u5f15\u7528\u7a97\u53e3 iframe.contentwindow \u6216 window.open\u8fd4\u56de\u7684\u5bf9\u8c61<br \/>\nmessage \u4e3a\u8981\u4f20\u9012\u7684\u6570\u636e<br \/>\ntargetOrigin \u4e3a\u76ee\u6807\u6e90<\/p>\n<pre>\/\/ http:\/\/127.0.0.1:80\r\nvar iframe = document.createElement('iframe')\r\niframe.onload = function(){\r\n var popup = iframe.contentWindow\r\n popup.postMessage(\"hello\", \"http:\/\/127.0.0.1:5000\");\r\n}\r\niframe.src = 'http:\/\/127.0.0.1:5000\/lab\/postMessage'\r\ndocument.body.appendChild(iframe)\r\n\/\/ \u76d1\u542c\u8fd4\u56de\u7684postMessage\r\nwindow.addEventListener(\"message\", function(event){\r\n if (event.origin !== \"http:\/\/127.0.0.1:5000\") return;\r\n console.log(event.data)\r\n}, false)\r\n\/\/ http:\/\/127.0.0.1:5000\/lab\/postMessage\r\nwindow.addEventListener(\"message\", function(event){\r\n \/\/ \u9a8c\u8bc1\u6d88\u606f\u6765\u6e90\r\n if (event.origin !== \"http:\/\/127.0.0.1\") return;\r\n console.log(event.source); \/\/ \u6d88\u606f\u6e90 popup\r\n console.log(event.origin); \/\/ \u6d88\u606f\u6e90URI https:\/\/secure.example.net \r\n console.log(event.data); \/\/ \u6765\u81ea\u6d88\u606f\u6e90\u7684\u6570\u636e hello\r\n \/\/ \u8fd4\u56de\u6570\u636e\r\n var message = 'world';\r\n event.source.postMessage(message, event.origin);\r\n}, false);<\/pre>\n<p>\u63a8\u8350\u4f7f\u7528\u63d2\u4ef6\uff1a\u300a<a href=\"https:\/\/sdeno.com\/?p=5058\" target=\"_blank\">iframe\u8de8\u57df\u76f8\u4e92\u4f20\u503c\u2013messageEvent.js<\/a>\u300b<\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #ff0000;\">\u00a05.CORS<\/span><\/p>\n<p>\u5b83\u5141\u8bb8\u4e00\u4e2a\u57df\u4e0a\u7684\u811a\u672c\u5411\u53e6\u4e00\u4e2a\u57df\u63d0\u4ea4\u8de8\u57df AJAX \u8bf7\u6c42\u3002\u5b9e\u73b0\u6b64\u529f\u80fd\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u7531\u670d\u52a1\u5668\u53d1\u9001\u4e00\u4e2a\u54cd\u5e94\u6807\u5934\u5373\u53ef\u3002<\/p>\n<p>CORS\uff08\u8de8\u57df\u8d44\u6e90\u5171\u4eab\uff09\u662f\u4e00\u79cd\u8de8\u57df\u8bbf\u95ee\u7684\u673a\u5236\uff0c\u53ef\u4ee5\u8ba9AJAX\u5b9e\u73b0\u8de8\u57df\u8bbf\u95ee\u3002\u5b83\u5141\u8bb8\u4e00\u4e2a\u57df\u4e0a\u7684\u811a\u672c\u5411\u53e6\u4e00\u4e2a\u57df\u63d0\u4ea4\u8de8\u57df AJAX \u8bf7\u6c42\u3002\u5b9e\u73b0\u6b64\u529f\u80fd\u975e\u5e38\u7b80\u5355\uff0c\u53ea\u9700\u7531\u670d\u52a1\u5668\u53d1\u9001\u4e00\u4e2a\u54cd\u5e94\u6807\u5934\u5373\u53ef\u3002<\/p>\n<pre>\/\/\u5728\u670d\u52a1\u5668\u7aef \u6700\u524d\u9762\u6dfb\u52a0\r\nAccess-Control-Allow-Origin: * \/\/ \u5141\u8bb8\u6765\u81ea\u4efb\u4f55\u57df\u7684\u8bf7\u6c42\r\n\u6216\u8005\r\nAccess-Control-Allow-Origin: http:\/\/funteas.com\/ \/\/ \u4ec5\u5141\u8bb8\u6765\u81eahttp:\/\/funteas.com\/\u7684\u8bf7\u6c42<\/pre>\n<p>\u5f53\u5ba2\u6237\u7aef\u7684ajax\u8bf7\u6c42\u7684url\u4e3a\u5176\u4ed6\u57df\u65f6\uff0c\u5bf9\u4e8e\u652f\u6301CORS\u7684\u6d4f\u89c8\u5668\uff0c\u8bf7\u6c42\u5934\u4f1a\u81ea\u52a8\u6dfb\u52a0Origin\uff0c\u503c\u4e3a\u5f53\u524dhost<\/p>\n<pre>var xhr = new XMLHttpRequest();\r\nvar url = 'http:\/\/bar.other\/resources\/public-data\/';\r\nxhr.open('GET', url, true);\r\nxhr.send();<\/pre>\n<p>CORS\u9ed8\u8ba4\u4e0d\u53d1\u9001cookie\uff0c\u5982\u679c\u8981\u53d1\u9001cookie\uff0c\u9700\u8981\u8bbe\u7f6ewithCredentials<\/p>\n<pre>var xhr = new XMLHttpRequest();\r\nxhr.withCredentials = true;<\/pre>\n<p>\u540c\u65f6\uff0c\u670d\u52a1\u7aef\u4e5f\u8981\u8bbe\u7f6e<\/p>\n<pre>Access-Control-Allow-Credentials: true<\/pre>\n<p>\u53c2\u8003\u300a<a href=\"https:\/\/sdeno.com\/?p=4815\" target=\"_blank\">\u63a8\u8350\u770bphp header \u8de8\u57df<\/a>\u300b<\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"http:\/\/mp.weixin.qq.com\/s?__biz=MzAwNjI5MTYyMw==&amp;mid=2651493337&amp;idx=1&amp;sn=120bd45026c18659b025232c95b06a69&amp;chksm=80f19a11b78613076c53026bc3d7d8f4d0ac52701854f2c78072d8920998ac5506a07592e997&amp;scene=0#wechat_redirect\" target=\"_blank\">http:\/\/mp.weixin.qq.com\/s?__biz=MzAwNjI5MTYyMw==&amp;mid=2651493337&amp;idx=1&amp;sn=120bd45026c18659b025232c95b06a69&amp;chksm=80f19a11b78613076c53026bc3d7d8f4d0ac52701854f2c78072d8920998ac5506a07592e997&amp;scene=0#wechat_redirect<\/a><\/p>\n<p>&nbsp;<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>URL \u7ed3\u679c \u539f\u56e0 http:\/\/store.company.com\/dir2\/other.html Succ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-5505","post","type-post","status-publish","format-standard","hentry","category-11"],"_links":{"self":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/5505","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5505"}],"version-history":[{"count":0,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/5505\/revisions"}],"wp:attachment":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5505"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5505"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5505"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}