{"id":3218,"date":"2014-11-05T16:20:41","date_gmt":"2014-11-05T08:20:41","guid":{"rendered":"https:\/\/sdeno.com\/?p=3218"},"modified":"2014-11-05T16:20:41","modified_gmt":"2014-11-05T08:20:41","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":"https:\/\/sdeno.com\/?p=3218","title":{"rendered":"JavaScript\u8de8\u57df\u603b\u7ed3\u4e0e\u89e3\u51b3\u529e\u6cd5"},"content":{"rendered":"<h1 class=\"postTitle\" style=\"font-weight: bold; color: #000000;\"><a id=\"cb_post_title_url\" class=\"postTitle2\" style=\"color: #399ab2;\" href=\"http:\/\/www.cnblogs.com\/rainman\/archive\/2011\/02\/20\/1959325.html\">JavaScript\u8de8\u57df\u603b\u7ed3\u4e0e\u89e3\u51b3\u529e\u6cd5<\/a><\/h1>\n<div class=\"clear\" style=\"color: #333333;\"><\/div>\n<div class=\"postBody\" style=\"color: #333333;\">\n<div id=\"cnblogs_post_body\">\n<ul class=\"catalogue\">\n<li><a style=\"color: #075db3;\" href=\"http:\/\/www.cnblogs.com\/rainman\/archive\/2011\/02\/20\/1959325.html#m0\">\u4ec0\u4e48\u662f\u8de8\u57df<\/a><\/li>\n<li><a style=\"color: #075db3;\" href=\"http:\/\/www.cnblogs.com\/rainman\/archive\/2011\/02\/20\/1959325.html#m1\">1\u3001document.domain+iframe\u7684\u8bbe\u7f6e<\/a><\/li>\n<li><a style=\"color: #075db3;\" href=\"http:\/\/www.cnblogs.com\/rainman\/archive\/2011\/02\/20\/1959325.html#m2\">2\u3001\u52a8\u6001\u521b\u5efascript<\/a><\/li>\n<li><a style=\"color: #075db3;\" href=\"http:\/\/www.cnblogs.com\/rainman\/archive\/2011\/02\/20\/1959325.html#m3\">3\u3001\u5229\u7528iframe\u548clocation.hash<\/a><\/li>\n<li><a style=\"color: #075db3;\" href=\"http:\/\/www.cnblogs.com\/rainman\/archive\/2011\/02\/20\/1959325.html#m4\">4\u3001window.name\u5b9e\u73b0\u7684\u8de8\u57df\u6570\u636e\u4f20\u8f93<\/a><\/li>\n<li><a style=\"color: #075db3;\" href=\"http:\/\/www.cnblogs.com\/rainman\/archive\/2011\/02\/20\/1959325.html#m5\">5\u3001\u4f7f\u7528HTML5 postMessage<\/a><\/li>\n<li><a style=\"color: #075db3;\" href=\"http:\/\/www.cnblogs.com\/rainman\/archive\/2011\/02\/20\/1959325.html#m6\">6\u3001\u5229\u7528flash<\/a><\/li>\n<\/ul>\n<div class=\"rainman-post\">\n<p>\u672c\u6587\u6765\u81ea\u7f51\u7edc\uff08http:\/\/f2e.me\/200904\/cross-scripting\/\uff0c\u8be5\u7f51\u5740\u5df2\u4e0d\u80fd\u8bbf\u95ee\uff09\uff0c\u4ec5\u4f5c\u4e2a\u4eba\u8bfb\u4e66\u7b14\u8bb0\u4e4b\u7528\uff0c\u5e76\u7a0d\u4f5c\u4fee\u6539\u548c\u8865\u5145\u3002<\/p>\n<p><a style=\"color: #075db3;\" href=\"http:\/\/www.cnblogs.com\/rainman\/archive\/2011\/02\/20\/1959325.html#\" name=\"m0\"><\/a><\/p>\n<h3 style=\"font-weight: bold; color: #000000;\">\u4ec0\u4e48\u662f\u8de8\u57df<\/h3>\n<p>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<\/p>\n<p>\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\u66f4\u8be6\u7ec6\u7684\u8bf4\u660e\u53ef\u4ee5\u770b\u4e0b\u8868\uff1a<\/p>\n<table class=\"border\">\n<tbody>\n<tr>\n<th style=\"font-weight: bold; color: #000000;\">URL<\/th>\n<th style=\"font-weight: bold; color: #000000;\">\u8bf4\u660e<\/th>\n<th style=\"font-weight: bold; color: #000000;\">\u662f\u5426\u5141\u8bb8\u901a\u4fe1<\/th>\n<\/tr>\n<tr>\n<td>http:\/\/www.a.com\/a.js<br \/>\nhttp:\/\/www.a.com\/b.js<\/td>\n<td>\u540c\u4e00\u57df\u540d\u4e0b<\/td>\n<td>\u5141\u8bb8<\/td>\n<\/tr>\n<tr>\n<td>http:\/\/www.a.com\/lab\/a.js<br \/>\nhttp:\/\/www.a.com\/script\/b.js<\/td>\n<td>\u540c\u4e00\u57df\u540d\u4e0b\u4e0d\u540c\u6587\u4ef6\u5939<\/td>\n<td>\u5141\u8bb8<\/td>\n<\/tr>\n<tr>\n<td>http:\/\/www.a.com:8000\/a.js<br \/>\nhttp:\/\/www.a.com\/b.js<\/td>\n<td>\u540c\u4e00\u57df\u540d\uff0c\u4e0d\u540c\u7aef\u53e3<\/td>\n<td>\u4e0d\u5141\u8bb8<\/td>\n<\/tr>\n<tr>\n<td>http:\/\/www.a.com\/a.js<br \/>\nhttps:\/\/www.a.com\/b.js<\/td>\n<td>\u540c\u4e00\u57df\u540d\uff0c\u4e0d\u540c\u534f\u8bae<\/td>\n<td>\u4e0d\u5141\u8bb8<\/td>\n<\/tr>\n<tr>\n<td>http:\/\/www.a.com\/a.js<br \/>\nhttp:\/\/70.32.92.74\/b.js<\/td>\n<td>\u57df\u540d\u548c\u57df\u540d\u5bf9\u5e94ip<\/td>\n<td>\u4e0d\u5141\u8bb8<\/td>\n<\/tr>\n<tr>\n<td>http:\/\/www.a.com\/a.js<br \/>\nhttp:\/\/script.a.com\/b.js<\/td>\n<td>\u4e3b\u57df\u76f8\u540c\uff0c\u5b50\u57df\u4e0d\u540c<\/td>\n<td>\u4e0d\u5141\u8bb8<\/td>\n<\/tr>\n<tr>\n<td>http:\/\/www.a.com\/a.js<br \/>\nhttp:\/\/a.com\/b.js<\/td>\n<td>\u540c\u4e00\u57df\u540d\uff0c\u4e0d\u540c\u4e8c\u7ea7\u57df\u540d\uff08\u540c\u4e0a\uff09<\/td>\n<td>\u4e0d\u5141\u8bb8\uff08cookie\u8fd9\u79cd\u60c5\u51b5\u4e0b\u4e5f\u4e0d\u5141\u8bb8\u8bbf\u95ee\uff09<\/td>\n<\/tr>\n<tr>\n<td>http:\/\/www.cnblogs.com\/a.js<br \/>\nhttp:\/\/www.a.com\/b.js<\/td>\n<td>\u4e0d\u540c\u57df\u540d<\/td>\n<td>\u4e0d\u5141\u8bb8<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<dl>\n<dt style=\"font-weight: bold;\">\u7279\u522b\u6ce8\u610f\u4e24\u70b9\uff1a<\/dt>\n<dd>\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<\/dd>\n<dd>\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<br \/>\n\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<\/dd>\n<\/dl>\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\u300a<a style=\"color: #075db3;\" href=\"http:\/\/developer.yahoo.com\/javascript\/howto-proxy.html\" target=\"_blank\">JavaScript: Use a Web Proxy for Cross-Domain XMLHttpRequest Calls<\/a>\u300b<\/p>\n<p><a style=\"color: #075db3;\" href=\"http:\/\/www.cnblogs.com\/rainman\/archive\/2011\/02\/20\/1959325.html#\" name=\"m1\"><\/a><\/p>\n<h3 style=\"font-weight: bold; color: #000000;\">1\u3001document.domain+iframe\u7684\u8bbe\u7f6e<\/h3>\n<p><span class=\"highlight\">\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<\/span>\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\u4e0adocument.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<\/p>\n<p>www.a.com\u4e0a\u7684a.html<\/p>\n<div class=\"rainman-code\">\n<pre style=\"color: #0c3e64;\">document.domain = 'a.com';\r\nvar ifr = document.createElement('iframe');\r\nifr.src = 'http:\/\/script.a.com\/b.html';\r\nifr.style.display = 'none';\r\ndocument.body.appendChild(ifr);\r\nifr.onload = function(){\r\n    var doc = ifr.contentDocument || ifr.contentWindow.document;\r\n    \/\/ \u5728\u8fd9\u91cc\u64cd\u7eb5b.html\r\n    alert(doc.getElementsByTagName(\"h1\")[0].childNodes[0].nodeValue);\r\n};<\/pre>\n<\/div>\n<p>script.a.com\u4e0a\u7684b.html<\/p>\n<div class=\"rainman-code\">\n<pre style=\"color: #0c3e64;\">document.domain = 'a.com';<\/pre>\n<\/div>\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<\/p>\n<p>\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<\/p>\n<dl>\n<dt style=\"font-weight: bold;\">\u95ee\u9898\uff1a<\/dt>\n<dd>1\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<\/dd>\n<dd>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<\/dd>\n<\/dl>\n<p><a style=\"color: #075db3;\" href=\"http:\/\/www.cnblogs.com\/rainman\/archive\/2011\/02\/20\/1959325.html#\" name=\"m2\"><\/a><\/p>\n<h3 style=\"font-weight: bold; color: #000000;\">2\u3001\u52a8\u6001\u521b\u5efascript<\/h3>\n<p><span class=\"highlight\">\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<\/span>\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\u7684<a style=\"color: #075db3;\" href=\"http:\/\/developer.yahoo.com\/yui\/get\/\" target=\"_blank\">Get Utility<\/a><\/p>\n<p>\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<\/p>\n<div class=\"rainman-code\">\n<pre style=\"color: #0c3e64;\">js.onload = js.onreadystatechange = function() {\r\n    if (!this.readyState || this.readyState === 'loaded' || this.readyState === 'complete') {\r\n        \/\/ callback\u5728\u6b64\u5904\u6267\u884c\r\n        js.onload = js.onreadystatechange = null;\r\n    }\r\n};<\/pre>\n<\/div>\n<p><a style=\"color: #075db3;\" href=\"http:\/\/www.cnblogs.com\/rainman\/archive\/2011\/02\/20\/1959325.html#\" name=\"m3\"><\/a><\/p>\n<h3 style=\"font-weight: bold; color: #000000;\">3\u3001\u5229\u7528iframe\u548clocation.hash<\/h3>\n<p>\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\u7684cs2.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\u7684cs2.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<span class=\"gray\">\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<\/span>\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<\/p>\n<p>\u5148\u662fa.com\u4e0b\u7684\u6587\u4ef6cs1.html\u6587\u4ef6\uff1a<\/p>\n<div class=\"rainman-code\">\n<pre style=\"color: #0c3e64;\">function startRequest(){\r\n    var ifr = document.createElement('iframe');\r\n    ifr.style.display = 'none';\r\n    ifr.src = 'http:\/\/www.cnblogs.com\/lab\/cscript\/cs2.html#paramdo';\r\n    document.body.appendChild(ifr);\r\n}\r\n\r\nfunction checkHash() {\r\n    try {\r\n        var data = location.hash ? location.hash.substring(1) : '';\r\n        if (console.log) {\r\n            console.log('Now the data is '+data);\r\n        }\r\n    } catch(e) {};\r\n}\r\nsetInterval(checkHash, 2000);<\/pre>\n<\/div>\n<p>cnblogs.com\u57df\u540d\u4e0b\u7684cs2.html:<\/p>\n<div class=\"rainman-code\">\n<pre style=\"color: #0c3e64;\">\/\/\u6a21\u62df\u4e00\u4e2a\u7b80\u5355\u7684\u53c2\u6570\u5904\u7406\u64cd\u4f5c\r\nswitch(location.hash){\r\n    case '#paramdo':\r\n        callBack();\r\n        break;\r\n    case '#paramset':\r\n        \/\/do something\u2026\u2026\r\n        break;\r\n}\r\n\r\nfunction callBack(){\r\n    try {\r\n        parent.location.hash = 'somedata';\r\n    } catch (e) {\r\n        \/\/ ie\u3001chrome\u7684\u5b89\u5168\u673a\u5236\u65e0\u6cd5\u4fee\u6539parent.location.hash\uff0c\r\n        \/\/ \u6240\u4ee5\u8981\u5229\u7528\u4e00\u4e2a\u4e2d\u95f4\u7684cnblogs\u57df\u4e0b\u7684\u4ee3\u7406iframe\r\n        var ifrproxy = document.createElement('iframe');\r\n        ifrproxy.style.display = 'none';\r\n        ifrproxy.src = 'http:\/\/a.com\/test\/cscript\/cs3.html#somedata';    <span class=\"green\">\/\/ \u6ce8\u610f\u8be5\u6587\u4ef6\u5728\"a.com\"\u57df\u4e0b<\/span>\r\n        document.body.appendChild(ifrproxy);\r\n    }\r\n}<\/pre>\n<\/div>\n<p>a.com\u4e0b\u7684\u57df\u540dcs3.html<\/p>\n<div class=\"rainman-code\">\n<pre style=\"color: #0c3e64;\">\/\/\u56e0\u4e3aparent.parent\u548c\u81ea\u8eab\u5c5e\u4e8e\u540c\u4e00\u4e2a\u57df\uff0c\u6240\u4ee5\u53ef\u4ee5\u6539\u53d8\u5176location.hash\u7684\u503c\r\nparent.parent.location.hash = self.location.hash.substring(1);<\/pre>\n<\/div>\n<p>\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<\/p>\n<p><a style=\"color: #075db3;\" href=\"http:\/\/www.cnblogs.com\/rainman\/archive\/2011\/02\/20\/1959325.html#\" name=\"m4\"><\/a><\/p>\n<h3 style=\"font-weight: bold; color: #000000;\">4\u3001window.name\u5b9e\u73b0\u7684\u8de8\u57df\u6570\u636e\u4f20\u8f93<\/h3>\n<p>\u6587\u7ae0\u8f83\u957f\u5217\u5728\u6b64\u5904\u4e0d\u4fbf\u4e8e\u9605\u8bfb\uff0c\u8be6\u7ec6\u8bf7\u770b\u00a0<a style=\"color: #075db3;\" href=\"http:\/\/www.cnblogs.com\/rainman\/archive\/2011\/02\/21\/1960044.html\" target=\"_blank\">window.name\u5b9e\u73b0\u7684\u8de8\u57df\u6570\u636e\u4f20\u8f93<\/a>\u3002<\/p>\n<p><a style=\"color: #075db3;\" href=\"http:\/\/www.cnblogs.com\/rainman\/archive\/2011\/02\/20\/1959325.html#\" name=\"m5\"><\/a><\/p>\n<h3 style=\"font-weight: bold; color: #000000;\">5\u3001\u4f7f\u7528HTML5 postMessage<\/h3>\n<p><a style=\"color: #075db3;\" href=\"http:\/\/dev.w3.org\/html5\/spec\/\" target=\"_blank\">HTML5<\/a>\u4e2d\u6700\u9177\u7684\u65b0\u529f\u80fd\u4e4b\u4e00\u5c31\u662f\u00a0<a style=\"color: #075db3;\" href=\"http:\/\/www.whatwg.org\/specs\/web-apps\/current-work\/#crossDocumentMessages\" target=\"_blank\">\u8de8\u6587\u6863\u6d88\u606f\u4f20\u8f93Cross Document Messaging<\/a>\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<\/p>\n<dl>\n<dt style=\"font-weight: bold;\">otherWindow.postMessage(message, targetOrigin);<\/dt>\n<dd><span class=\"green\">otherWindow:\u00a0<\/span>\u5bf9\u63a5\u6536\u4fe1\u606f\u9875\u9762\u7684window\u7684\u5f15\u7528\u3002\u53ef\u4ee5\u662f\u9875\u9762\u4e2diframe\u7684contentWindow\u5c5e\u6027\uff1b<a style=\"color: #075db3;\" href=\"https:\/\/developer.mozilla.org\/en\/DOM\/window.open\" target=\"_blank\">window.open<\/a>\u7684\u8fd4\u56de\u503c\uff1b\u901a\u8fc7name\u6216\u4e0b\u6807\u4ece<a style=\"color: #075db3;\" href=\"https:\/\/developer.mozilla.org\/en\/DOM\/window.frames\" target=\"_blank\">window.frames<\/a>\u53d6\u5230\u7684\u503c\u3002<br \/>\n<span class=\"green\">message:\u00a0<\/span>\u6240\u8981\u53d1\u9001\u7684\u6570\u636e\uff0cstring\u7c7b\u578b\u3002<br \/>\n<span class=\"green\">targetOrigin:\u00a0<\/span>\u7528\u4e8e\u9650\u5236otherWindow\uff0c\u201c*\u201d\u8868\u793a\u4e0d\u4f5c\u9650\u5236<\/dd>\n<\/dl>\n<p>a.com\/index.html\u4e2d\u7684\u4ee3\u7801\uff1a<\/p>\n<div class=\"rainman-code\">\n<pre style=\"color: #0c3e64;\">&lt;iframe id=\"ifr\" src=\"b.com\/index.html\"&gt;&lt;\/iframe&gt;\r\n&lt;script type=\"text\/javascript\"&gt;\r\nwindow.onload = function() {\r\n    var ifr = document.getElementById('ifr');\r\n    var targetOrigin = 'http:\/\/b.com';  <span class=\"green\">\/\/ \u82e5\u5199\u6210'http:\/\/b.com\/c\/proxy.html'\u6548\u679c\u4e00\u6837<\/span>\r\n                                        <span class=\"green\">\/\/ \u82e5\u5199\u6210'http:\/\/c.com'\u5c31\u4e0d\u4f1a\u6267\u884cpostMessage\u4e86<\/span>\r\n    ifr.contentWindow.postMessage('I was there!', targetOrigin);\r\n};\r\n&lt;\/script&gt;<\/pre>\n<\/div>\n<p>b.com\/index.html\u4e2d\u7684\u4ee3\u7801\uff1a<\/p>\n<div class=\"rainman-code\">\n<pre style=\"color: #0c3e64;\">&lt;script type=\"text\/javascript\"&gt;\r\n    window.addEventListener('message', function(event){\r\n        \/\/ \u901a\u8fc7origin\u5c5e\u6027\u5224\u65ad\u6d88\u606f\u6765\u6e90\u5730\u5740\r\n        if (event.origin == 'http:\/\/a.com') {\r\n            alert(event.data);    \/\/ \u5f39\u51fa\"I was there!\"\r\n            alert(event.source);  \/\/ \u5bf9a.com\u3001index.html\u4e2dwindow\u5bf9\u8c61\u7684\u5f15\u7528\r\n                                  \/\/ \u4f46\u7531\u4e8e\u540c\u6e90\u7b56\u7565\uff0c\u8fd9\u91ccevent.source\u4e0d\u53ef\u4ee5\u8bbf\u95eewindow\u5bf9\u8c61\r\n        }\r\n    }, false);\r\n&lt;\/script&gt;<\/pre>\n<\/div>\n<p>\u53c2\u8003\u6587\u7ae0\uff1a<a style=\"color: #075db3;\" href=\"http:\/\/www.grati.org\/?p=429\" target=\"_blank\">\u300a\u7cbe\u901aHTML5\u7f16\u7a0b\u300b\u7b2c\u4e94\u7ae0\u2014\u2014\u8de8\u6587\u6863\u6d88\u606f\u673a\u5236<\/a>\u3001<a style=\"color: #075db3;\" href=\"https:\/\/developer.mozilla.org\/en\/dom\/window.postmessage\" target=\"_blanks\">https:\/\/developer.mozilla.org\/en\/dom\/window.postmessage<\/a><\/p>\n<p><a style=\"color: #075db3;\" href=\"http:\/\/www.cnblogs.com\/rainman\/archive\/2011\/02\/20\/1959325.html#\" name=\"m6\"><\/a><\/p>\n<h3 style=\"font-weight: bold; color: #000000;\">6\u3001\u5229\u7528flash<\/h3>\n<p>\u8fd9\u662f\u4eceYUI3\u7684IO\u7ec4\u4ef6\u4e2d\u770b\u5230\u7684\u529e\u6cd5\uff0c\u5177\u4f53\u53ef\u89c1<a style=\"color: #075db3;\" href=\"http:\/\/developer.yahoo.com\/yui\/3\/io\/\" target=\"_blank\">http:\/\/developer.yahoo.com\/yui\/3\/io\/<\/a>\u3002<br \/>\n\u53ef\u4ee5\u770b\u5728Adobe Developer Connection\u770b\u5230\u66f4\u591a\u7684\u8de8\u57df\u4ee3\u7406\u6587\u4ef6\u89c4\u8303\uff1a<a style=\"color: #075db3;\" href=\"http:\/\/www.adobe.com\/devnet\/articles\/crossdomain_policy_file_spec.html\" target=\"_blank\">ross-Domain Policy File Specifications<\/a>\u3001<a style=\"color: #075db3;\" href=\"http:\/\/www.adobe.com\/devnet\/articles\/crossdomain_policy_file_spec.html\" target=\"_blank\">HTTP Headers Blacklist<\/a>\u3002<\/p>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>JavaScript\u8de8\u57df\u603b\u7ed3\u4e0e\u89e3\u51b3\u529e\u6cd5 \u4ec0\u4e48\u662f\u8de8\u57df 1\u3001document.domain+iframe\u7684\u8bbe\u7f6e 2 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[26,11],"tags":[],"class_list":["post-3218","post","type-post","status-publish","format-standard","hentry","category-javascript","category-11"],"_links":{"self":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/3218","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=3218"}],"version-history":[{"count":0,"href":"https:\/\/sdeno.com\/index.php?rest_route=\/wp\/v2\/posts\/3218\/revisions"}],"wp:attachment":[{"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3218"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3218"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sdeno.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3218"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}