{"id":1745,"date":"2017-03-28T08:33:08","date_gmt":"2017-03-28T00:33:08","guid":{"rendered":"http:\/\/www.qdabc.cn\/?p=1745"},"modified":"2017-03-28T08:33:08","modified_gmt":"2017-03-28T00:33:08","slug":"javascript-%e8%b7%a8%e5%9f%9f%e6%80%bb%e7%bb%93%e4%b8%8e%e8%a7%a3%e5%86%b3%e5%8a%9e%e6%b3%95","status":"publish","type":"post","link":"http:\/\/www.qdabc.cn\/?p=1745","title":{"rendered":"JavaScript \u8de8\u57df\u603b\u7ed3\u4e0e\u89e3\u51b3\u529e\u6cd5"},"content":{"rendered":"<p>\u4ec0\u4e48\u662f\u8de8\u57df<br \/>\nJavaScript\u51fa\u4e8e\u5b89\u5168\u65b9\u9762\u7684\u8003\u8651\uff0c\u4e0d\u5141\u8bb8\u8de8\u57df\u8c03\u7528\u5176\u4ed6\u9875\u9762\u7684\u5bf9\u8c61\u3002\u4f46\u5728\u5b89\u5168\u9650\u5236\u7684\u540c\u65f6\u4e5f\u7ed9\u6ce8\u5165iframe\u6216\u662fajax\u5e94\u7528\u4e0a\u5e26\u6765\u4e86\u4e0d\u5c11\u9ebb\u70e6\u3002\u8fd9\u91cc\u628a\u6d89\u53ca\u5230\u8de8\u57df\u7684\u4e00\u4e9b\u95ee\u9898\u7b80\u5355\u5730\u6574\u7406\u4e00\u4e0b\uff1a<br \/>\n\u9996\u5148\u4ec0\u4e48\u662f\u8de8\u57df\uff0c\u7b80\u5355\u5730\u7406\u89e3\u5c31\u662f\u56e0\u4e3aJavaScript\u540c\u6e90\u7b56\u7565\u7684\u9650\u5236\uff0ca.com \u57df\u540d\u4e0b\u7684js\u65e0\u6cd5\u64cd\u4f5cb.com\u6216\u662fc.a.com\u57df\u540d\u4e0b\u7684\u5bf9\u8c61\u3002<\/p>\n<p>\u7279\u522b\u6ce8\u610f\u4e24\u70b9\uff1a<br \/>\n\u7b2c\u4e00\uff0c\u5982\u679c\u662f\u534f\u8bae\u548c\u7aef\u53e3\u9020\u6210\u7684\u8de8\u57df\u95ee\u9898\u201c\u524d\u53f0\u201d\u662f\u65e0\u80fd\u4e3a\u529b\u7684\uff0c<\/p>\n<p>\u7b2c\u4e8c\uff1a\u5728\u8de8\u57df\u95ee\u9898\u4e0a\uff0c\u57df\u4ec5\u4ec5\u662f\u901a\u8fc7\u201cURL\u7684\u9996\u90e8\u201d\u6765\u8bc6\u522b\u800c\u4e0d\u4f1a\u53bb\u5c1d\u8bd5\u5224\u65ad\u76f8\u540c\u7684ip\u5730\u5740\u5bf9\u5e94\u7740\u4e24\u4e2a\u57df\u6216\u4e24\u4e2a\u57df\u662f\u5426\u5728\u540c\u4e00\u4e2aip\u4e0a\u3002<\/p>\n<p>\u201cURL\u7684\u9996\u90e8\u201d\u6307window.location.protocol +window.location.host\uff0c\u4e5f\u53ef\u4ee5\u7406\u89e3\u4e3a\u201cDomains, protocols and ports must match\u201d\u3002<\/p>\n<p>\u63a5\u4e0b\u6765\u7b80\u5355\u5730\u603b\u7ed3\u4e00\u4e0b\u5728\u201c\u524d\u53f0\u201d\u4e00\u822c\u5904\u7406\u8de8\u57df\u7684\u529e\u6cd5\uff0c\u540e\u53f0proxy\u8fd9\u79cd\u65b9\u6848\u7275\u6d89\u5230\u540e\u53f0\u914d\u7f6e\uff0c\u8fd9\u91cc\u5c31\u4e0d\u9610\u8ff0\u4e86\uff0c\u6709\u5174\u8da3\u7684\u53ef\u4ee5\u770b\u770byahoo\u7684\u8fd9\u7bc7\u6587\u7ae0\uff1a\u300aJavaScript: Use a Web Proxy for Cross-Domain XMLHttpRequest Calls\u300b<br \/>\n1\u3001document.domain+iframe\u7684\u8bbe\u7f6e<br \/>\n\u5bf9\u4e8e\u4e3b\u57df\u76f8\u540c\u800c\u5b50\u57df\u4e0d\u540c\u7684\u4f8b\u5b50\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbe\u7f6edocument.domain\u7684\u529e\u6cd5\u6765\u89e3\u51b3\u3002 \u5177\u4f53\u7684\u505a\u6cd5\u662f\u53ef\u4ee5\u5728http:\/\/www.a.com\/a.html\u548chttp:\/\/script.a.com\/b.html\u4e24\u4e2a\u6587\u4ef6\u4e2d\u5206\u522b\u52a0\u4e0a document.domain = \u2018a.com\u2019\uff1b\u7136\u540e\u901a\u8fc7a.html\u6587\u4ef6\u4e2d\u521b\u5efa\u4e00\u4e2aiframe\uff0c\u53bb\u63a7\u5236iframe\u7684contentDocument\uff0c\u8fd9\u6837\u4e24\u4e2ajs\u6587\u4ef6\u4e4b\u95f4\u5c31\u53ef\u4ee5 \u201c\u4ea4\u4e92\u201d\u4e86\u3002\u5f53\u7136\u8fd9\u79cd\u529e\u6cd5\u53ea\u80fd\u89e3\u51b3\u4e3b\u57df\u76f8\u540c\u800c\u4e8c\u7ea7\u57df\u540d\u4e0d\u540c\u7684\u60c5\u51b5\uff0c\u5982\u679c\u4f60\u5f02\u60f3\u5929\u5f00\u7684\u628ascript.a.com\u7684domian\u8bbe\u4e3aalibaba.com \u90a3\u663e\u7136\u662f\u4f1a\u62a5\u9519\u5730\uff01\u4ee3\u7801\u5982\u4e0b\uff1a<br \/>\nwww.a.com\u4e0a\u7684a.html<br \/>\ndocument.domain = &#8216;a.com&#8217;;<\/p>\n<p>var ifr = document.createElement(&#8216;iframe&#8217;);<\/p>\n<p>ifr.src = &#8216;http:\/\/script.a.com\/b.html&#8217;;<\/p>\n<p>ifr.style.display = &#8216;none&#8217;;<\/p>\n<p>document.body.appendChild(ifr);<\/p>\n<p>ifr.onload = function(){<\/p>\n<p>&nbsp; &nbsp; var doc = ifr.contentDocument || ifr.contentWindow.document;<\/p>\n<p>&nbsp; &nbsp; \/\/ \u5728\u8fd9\u91cc\u64cd\u7eb5b.html<\/p>\n<p>&nbsp; &nbsp; alert(doc.getElementsByTagName(&#8220;h1&#8243;)[0].childNodes[0].nodeValue);<\/p>\n<p>};<br \/>\nscript.a.com\u4e0a\u7684b.html<br \/>\ndocument.domain = &#8216;a.com&#8217;;<\/p>\n<p>&nbsp;<\/p>\n<p>\u8fd9\u79cd\u65b9\u5f0f\u9002\u7528\u4e8e{www.kuqin.com, kuqin.com, script.kuqin.com, css.kuqin.com}\u4e2d\u7684\u4efb\u4f55\u9875\u9762\u76f8\u4e92\u901a\u4fe1\u3002<br \/>\n\u5907\u6ce8\uff1a\u67d0\u4e00\u9875\u9762\u7684domain\u9ed8\u8ba4\u7b49\u4e8ewindow.location.hostname\u3002\u4e3b\u57df\u540d\u662f\u4e0d\u5e26www\u7684\u57df\u540d\uff0c\u4f8b\u5982a.com\uff0c\u4e3b\u57df\u540d\u524d\u9762\u5e26\u524d\u7f00\u7684\u901a\u5e38\u90fd\u4e3a\u4e8c\u7ea7\u57df\u540d\u6216\u591a\u7ea7\u57df\u540d\uff0c\u4f8b\u5982www.a.com\u5176\u5b9e\u662f\u4e8c\u7ea7\u57df\u540d\u3002 domain\u53ea\u80fd\u8bbe\u7f6e\u4e3a\u4e3b\u57df\u540d\uff0c\u4e0d\u53ef\u4ee5\u5728b.a.com\u4e2d\u5c06domain\u8bbe\u7f6e\u4e3ac.a.com\u3002<br \/>\n\u95ee\u9898\uff1a<br \/>\n1\u3001\u5b89\u5168\u6027\uff0c\u5f53\u4e00\u4e2a\u7ad9\u70b9\uff08b.a.com\uff09\u88ab\u653b\u51fb\u540e\uff0c\u53e6\u4e00\u4e2a\u7ad9\u70b9\uff08c.a.com\uff09\u4f1a\u5f15\u8d77\u5b89\u5168\u6f0f\u6d1e\u3002<\/p>\n<p>2\u3001\u5982\u679c\u4e00\u4e2a\u9875\u9762\u4e2d\u5f15\u5165\u591a\u4e2aiframe\uff0c\u8981\u60f3\u80fd\u591f\u64cd\u4f5c\u6240\u6709iframe\uff0c\u5fc5\u987b\u90fd\u5f97\u8bbe\u7f6e\u76f8\u540cdomain\u3002<br \/>\n2\u3001\u52a8\u6001\u521b\u5efascript<br \/>\n\u867d\u7136\u6d4f\u89c8\u5668\u9ed8\u8ba4\u7981\u6b62\u4e86\u8de8\u57df\u8bbf\u95ee\uff0c\u4f46\u5e76\u4e0d\u7981\u6b62\u5728\u9875\u9762\u4e2d\u5f15\u7528\u5176\u4ed6\u57df\u7684JS\u6587\u4ef6\uff0c\u5e76\u53ef\u4ee5\u81ea\u7531\u6267\u884c\u5f15\u5165\u7684JS\u6587\u4ef6\u4e2d\u7684function\uff08\u5305\u62ec\u64cd\u4f5ccookie\u3001Dom\u7b49\u7b49\uff09\u3002\u6839\u636e\u8fd9\u4e00\u70b9\uff0c\u53ef\u4ee5\u65b9\u4fbf\u5730\u901a\u8fc7\u521b\u5efascript\u8282\u70b9\u7684\u65b9\u6cd5\u6765\u5b9e\u73b0\u5b8c\u5168\u8de8\u57df\u7684\u901a\u4fe1\u3002\u5177\u4f53\u7684\u505a\u6cd5\u53ef\u4ee5\u53c2\u8003YUI\u7684Get Utility<br \/>\n\u8fd9\u91cc\u5224\u65adscript\u8282\u70b9\u52a0\u8f7d\u5b8c\u6bd5\u8fd8\u662f\u86ee\u6709\u610f\u601d\u7684\uff1aie\u53ea\u80fd\u901a\u8fc7script\u7684readystatechange\u5c5e\u6027\uff0c\u5176\u5b83\u6d4f\u89c8\u5668\u662fscript\u7684load\u4e8b\u4ef6\u3002\u4ee5\u4e0b\u662f\u90e8\u5206\u5224\u65adscript\u52a0\u8f7d\u5b8c\u6bd5\u7684\u65b9\u6cd5\u3002<br \/>\njs.onload = js.onreadystatechange = function() {<\/p>\n<p>&nbsp; &nbsp; if (!this.readyState || this.readyState === &#8216;loaded&#8217; || this.readyState === &#8216;complete&#8217;) {<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; \/\/ callback\u5728\u6b64\u5904\u6267\u884c<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; js.onload = js.onreadystatechange = null;<\/p>\n<p>&nbsp; &nbsp; }<\/p>\n<p>};<br \/>\n3\u3001\u5229\u7528iframe\u548clocation.hash<br \/>\n\u8fd9\u4e2a\u529e\u6cd5\u6bd4\u8f83\u7ed5\uff0c\u4f46\u662f\u53ef\u4ee5\u89e3\u51b3\u5b8c\u5168\u8de8\u57df\u60c5\u51b5\u4e0b\u7684\u811a\u6b65\u7f6e\u6362\u95ee\u9898\u3002\u539f\u7406\u662f\u5229\u7528location.hash\u6765\u8fdb\u884c\u4f20\u503c\u3002\u5728url\uff1a http:\/\/a.com#helloword\u4e2d\u7684\u2018#helloworld\u2019\u5c31\u662flocation.hash\uff0c\u6539\u53d8hash\u5e76\u4e0d\u4f1a\u5bfc\u81f4\u9875\u9762\u5237\u65b0\uff0c\u6240\u4ee5\u53ef \u4ee5\u5229\u7528hash\u503c\u6765\u8fdb\u884c\u6570\u636e\u4f20\u9012\uff0c\u5f53\u7136\u6570\u636e\u5bb9\u91cf\u662f\u6709\u9650\u7684\u3002\u5047\u8bbe\u57df\u540da.com\u4e0b\u7684\u6587\u4ef6cs1.html\u8981\u548ccnblogs.com\u57df\u540d\u4e0b\u7684 cs2.html\u4f20\u9012\u4fe1\u606f\uff0ccs1.html\u9996\u5148\u521b\u5efa\u81ea\u52a8\u521b\u5efa\u4e00\u4e2a\u9690\u85cf\u7684iframe\uff0ciframe\u7684src\u6307\u5411cnblogs.com\u57df\u540d\u4e0b\u7684 cs2.html\u9875\u9762\uff0c\u8fd9\u65f6\u7684hash\u503c\u53ef\u4ee5\u505a\u53c2\u6570\u4f20\u9012\u7528\u3002cs2.html\u54cd\u5e94\u8bf7\u6c42\u540e\u518d\u5c06\u901a\u8fc7\u4fee\u6539cs1.html\u7684hash\u503c\u6765\u4f20\u9012\u6570\u636e\uff08\u7531\u4e8e\u4e24\u4e2a\u9875\u9762\u4e0d\u5728\u540c\u4e00\u4e2a\u57df\u4e0bIE\u3001Chrome\u4e0d\u5141\u8bb8\u4fee\u6539parent.location.hash\u7684\u503c\uff0c\u6240\u4ee5\u8981\u501f\u52a9\u4e8ea.com\u57df\u540d\u4e0b\u7684\u4e00\u4e2a\u4ee3\u7406iframe\uff1bFirefox\u53ef\u4ee5\u4fee\u6539\uff09\u3002\u540c\u65f6\u5728cs1.html\u4e0a\u52a0\u4e00\u4e2a\u5b9a\u65f6\u5668\uff0c\u9694\u4e00\u6bb5\u65f6\u95f4\u6765\u5224\u65adlocation.hash\u7684\u503c\u6709\u6ca1\u6709\u53d8\u5316\uff0c\u4e00\u70b9\u6709\u53d8\u5316\u5219\u83b7\u53d6\u83b7\u53d6hash\u503c\u3002\u4ee3\u7801\u5982\u4e0b\uff1a<br \/>\n\u5148\u662fa.com\u4e0b\u7684\u6587\u4ef6cs1.html\u6587\u4ef6\uff1a<br \/>\nfunction startRequest(){<\/p>\n<p>&nbsp; &nbsp; var ifr = document.createElement(&#8216;iframe&#8217;);<\/p>\n<p>&nbsp; &nbsp; ifr.style.display = &#8216;none&#8217;;<\/p>\n<p>&nbsp; &nbsp; ifr.src = &#8216;http:\/\/www.cnblogs.com\/lab\/cscript\/cs2.html#paramdo&#8217;;<\/p>\n<p>&nbsp; &nbsp; document.body.appendChild(ifr);<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>function checkHash() {<\/p>\n<p>&nbsp; &nbsp; try {<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; var data = location.hash ? location.hash.substring(1) : &#8221;;<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; if (console.log) {<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; console.log(&#8216;Now the data is &#8216;+data);<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; }<\/p>\n<p>&nbsp; &nbsp; } catch(e) {};<\/p>\n<p>}<\/p>\n<p>setInterval(checkHash, 2000);&nbsp;<br \/>\ncnblogs.com\u57df\u540d\u4e0b\u7684cs2.html:<br \/>\n\/\/\u6a21\u62df\u4e00\u4e2a\u7b80\u5355\u7684\u53c2\u6570\u5904\u7406\u64cd\u4f5c<\/p>\n<p>switch(location.hash){<\/p>\n<p>&nbsp; &nbsp; case &#8216;#paramdo&#8217;:<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; callBack();<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; break;<\/p>\n<p>&nbsp; &nbsp; case &#8216;#paramset&#8217;:<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; \/\/do something\u2026\u2026<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; break;<\/p>\n<p>}<\/p>\n<p>&nbsp;<\/p>\n<p>function callBack(){<\/p>\n<p>&nbsp; &nbsp; try {<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; parent.location.hash = &#8216;somedata&#8217;;<\/p>\n<p>&nbsp; &nbsp; } catch (e) {<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; \/\/ ie\u3001chrome\u7684\u5b89\u5168\u673a\u5236\u65e0\u6cd5\u4fee\u6539parent.location.hash\uff0c<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; \/\/ \u6240\u4ee5\u8981\u5229\u7528\u4e00\u4e2a\u4e2d\u95f4\u7684cnblogs\u57df\u4e0b\u7684\u4ee3\u7406iframe<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; var ifrproxy = document.createElement(&#8216;iframe&#8217;);<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; ifrproxy.style.display = &#8216;none&#8217;;<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; ifrproxy.src = &#8216;http:\/\/a.com\/test\/cscript\/cs3.html#somedata&#8217;; &nbsp; &nbsp;\/\/ \u6ce8\u610f\u8be5\u6587\u4ef6\u5728&#8221;a.com&#8221;\u57df\u4e0b<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; document.body.appendChild(ifrproxy);<\/p>\n<p>&nbsp; &nbsp; }<\/p>\n<p>}<br \/>\na.com\u4e0b\u7684\u57df\u540dcs3.html<br \/>\n\/\/\u56e0\u4e3aparent.parent\u548c\u81ea\u8eab\u5c5e\u4e8e\u540c\u4e00\u4e2a\u57df\uff0c\u6240\u4ee5\u53ef\u4ee5\u6539\u53d8\u5176location.hash\u7684\u503c<\/p>\n<p>parent.parent.location.hash = self.location.hash.substring(1);<br \/>\n\u5f53\u7136\u8fd9\u6837\u505a\u4e5f\u5b58\u5728\u5f88\u591a\u7f3a\u70b9\uff0c\u8bf8\u5982\u6570\u636e\u76f4\u63a5\u66b4\u9732\u5728\u4e86url\u4e2d\uff0c\u6570\u636e\u5bb9\u91cf\u548c\u7c7b\u578b\u90fd\u6709\u9650\u7b49\u2026\u2026<br \/>\n4\u3001window.name\u5b9e\u73b0\u7684\u8de8\u57df\u6570\u636e\u4f20\u8f93<br \/>\n\u6587\u7ae0\u8f83\u957f\u5217\u5728\u6b64\u5904\u4e0d\u4fbf\u4e8e\u9605\u8bfb\uff0c\u8be6\u7ec6\u8bf7\u770b window.name\u5b9e\u73b0\u7684\u8de8\u57df\u6570\u636e\u4f20\u8f93\uff08http:\/\/www.cnblogs.com\/rainman\/archive\/2011\/02\/21\/1960044.html\uff09\u3002<br \/>\n5\u3001\u4f7f\u7528HTML5 postMessage<br \/>\nHTML5\u4e2d\u6700\u9177\u7684\u65b0\u529f\u80fd\u4e4b\u4e00\u5c31\u662f \u8de8\u6587\u6863\u6d88\u606f\u4f20\u8f93Cross Document Messaging\u3002 \u4e0b\u4e00\u4ee3\u6d4f\u89c8\u5668\u90fd\u5c06\u652f\u6301\u8fd9\u4e2a\u529f\u80fd\uff1aChrome 2.0+\u3001Internet Explorer 8.0+, Firefox 3.0+, Opera 9.6+, \u548c Safari 4.0+ \u3002 Facebook\u5df2\u7ecf\u4f7f\u7528\u4e86\u8fd9\u4e2a\u529f\u80fd\uff0c\u7528postMessage\u652f\u6301\u57fa\u4e8eweb\u7684\u5b9e\u65f6\u6d88\u606f\u4f20\u9012\u3002<br \/>\notherWindow.postMessage(message, targetOrigin);<\/p>\n<p>otherWindow: \u5bf9\u63a5\u6536\u4fe1\u606f\u9875\u9762\u7684window\u7684\u5f15\u7528\u3002\u53ef\u4ee5\u662f\u9875\u9762\u4e2diframe\u7684contentWindow\u5c5e\u6027\uff1bwindow.open\u7684\u8fd4\u56de\u503c\uff1b\u901a\u8fc7name\u6216\u4e0b\u6807\u4ecewindow.frames\u53d6\u5230\u7684\u503c\u3002<\/p>\n<p>message: \u6240\u8981\u53d1\u9001\u7684\u6570\u636e\uff0cstring\u7c7b\u578b\u3002<\/p>\n<p>targetOrigin: \u7528\u4e8e\u9650\u5236otherWindow\uff0c\u201c*\u201d\u8868\u793a\u4e0d\u4f5c\u9650\u5236<\/p>\n<p>a.com\/index.html\u4e2d\u7684\u4ee3\u7801\uff1a<br \/>\n&lt;iframe id=&#8221;ifr&#8221; src=&#8221;b.com\/index.html&#8221;&gt;&lt;\/iframe&gt;<\/p>\n<p>&lt;script type=&#8221;text\/javascript&#8221;&gt;<\/p>\n<p>window.onload = function() {<\/p>\n<p>&nbsp; &nbsp; var ifr = document.getElementById(&#8216;ifr&#8217;);<\/p>\n<p>&nbsp; &nbsp; var targetOrigin = &#8216;http:\/\/b.com&#8217;; &nbsp;\/\/ \u82e5\u5199\u6210&#8217;http:\/\/b.com\/c\/proxy.html&#8217;\u6548\u679c\u4e00\u6837<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/ \u82e5\u5199\u6210&#8217;http:\/\/c.com&#8217;\u5c31\u4e0d\u4f1a\u6267\u884cpostMessage\u4e86<\/p>\n<p>&nbsp; &nbsp; ifr.contentWindow.postMessage(&#8216;I was there!&#8217;, targetOrigin);<\/p>\n<p>};<\/p>\n<p>&lt;\/script&gt;&nbsp;<br \/>\nb.com\/index.html\u4e2d\u7684\u4ee3\u7801\uff1a<br \/>\n&lt;script type=&#8221;text\/javascript&#8221;&gt;<\/p>\n<p>&nbsp; &nbsp; window.addEventListener(&#8216;message&#8217;, function(event){<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; \/\/ \u901a\u8fc7origin\u5c5e\u6027\u5224\u65ad\u6d88\u606f\u6765\u6e90\u5730\u5740<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; if (event.origin == &#8216;http:\/\/a.com&#8217;) {<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert(event.data); &nbsp; &nbsp;\/\/ \u5f39\u51fa&#8221;I was there!&#8221;<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; alert(event.source); &nbsp;\/\/ \u5bf9a.com\u3001index.html\u4e2dwindow\u5bf9\u8c61\u7684\u5f15\u7528<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/ \u4f46\u7531\u4e8e\u540c\u6e90\u7b56\u7565\uff0c\u8fd9\u91ccevent.source\u4e0d\u53ef\u4ee5\u8bbf\u95eewindow\u5bf9\u8c61<\/p>\n<p>&nbsp; &nbsp; &nbsp; &nbsp; }<\/p>\n<p>&nbsp; &nbsp; }, false);<\/p>\n<p>&lt;\/script&gt;<br \/>\n\u53c2\u8003\u6587\u7ae0\uff1a\u300a\u7cbe\u901aHTML5\u7f16\u7a0b\u300b\u7b2c\u4e94\u7ae0\u8de8\u6587\u6863\u6d88\u606f\u673a\u5236\u3001https:\/\/developer.mozilla.org\/en\/dom\/window.postmessage<\/p>\n<p>6\u3001\u5229\u7528flash<br \/>\n\u8fd9\u662f\u4eceYUI3\u7684IO\u7ec4\u4ef6\u4e2d\u770b\u5230\u7684\u529e\u6cd5\uff0c\u5177\u4f53\u53ef\u89c1http:\/\/developer.yahoo.com\/yui\/3\/io\/\u3002<\/p>\n<p>\u53ef\u4ee5\u770b\u5728Adobe Developer Connection\u770b\u5230\u66f4\u591a\u7684\u8de8\u57df\u4ee3\u7406\u6587\u4ef6\u89c4\u8303\uff1aross-Domain Policy File Specifications\u3001HTTP Headers Blacklist\u3002<\/p>\n<p class=\"post-copyright\">\u6b22\u8fce\u5206\u4eab\u672c\u6587\uff0c\u8f6c\u8f7d\u8bf7\u4fdd\u7559\u51fa\u5904\uff1a<a href=\"http:\/\/www.qdabc.cn\">\u524d\u7aefABC<\/a> &raquo; <a href=\"http:\/\/www.qdabc.cn\/?p=1745\">JavaScript \u8de8\u57df\u603b\u7ed3\u4e0e\u89e3\u51b3\u529e\u6cd5<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>\u4ec0\u4e48\u662f\u8de8\u57df JavaScript\u51fa\u4e8e\u5b89\u5168\u65b9\u9762\u7684\u8003\u8651\uff0c\u4e0d\u5141\u8bb8\u8de8\u57df\u8c03\u7528\u5176\u4ed6\u9875\u9762\u7684\u5bf9\u8c61\u3002\u4f46\u5728\u5b89\u5168\u9650\u5236\u7684\u540c\u65f6\u4e5f\u7ed9\u6ce8\u5165iframe\u6216\u662fajax\u5e94\u7528\u4e0a\u5e26\u6765\u4e86\u4e0d\u5c11\u9ebb\u70e6\u3002\u8fd9\u91cc\u628a\u6d89\u53ca\u5230\u8de8\u57df\u7684\u4e00\u4e9b\u95ee\u9898\u7b80\u5355\u5730\u6574\u7406\u4e00\u4e0b\uff1a \u9996 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"_links":{"self":[{"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=\/wp\/v2\/posts\/1745"}],"collection":[{"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1745"}],"version-history":[{"count":1,"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=\/wp\/v2\/posts\/1745\/revisions"}],"predecessor-version":[{"id":1746,"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=\/wp\/v2\/posts\/1745\/revisions\/1746"}],"wp:attachment":[{"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1745"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1745"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.qdabc.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1745"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}