Previously written on the use of window.name to transfer data across the domain, the principle of the Location.hash method is similar to the use of Location.hash changes will not refresh the feature, by referencing the data page in Outland to modify the main page of the Location.hash to achieve the purpose of transmitting data.
Also three pages: 111cn.net/main.html (Home page), 111cn.net/proxy.html (Agent page), b.com/data.html (Data page in Outland)
1. main.html code for the home page of this domain
var iframe = document.createelement ("iframe");
IFRAME.SRC = "http://www.b.com/data.html";
if (window. VBArray) {//if it is IE
Iframe.onreadystatechange = function () {
if (iframe.readystate = = ' complete ') {
alert (Location.hash);
}
};
} else {
Iframe.onload = function () {
alert (Location.hash);
};
}
Document.body.appendChild (IFRAME);
2. The code for data.html in Outland is as follows
var data = "some datas";
try {
Parent.location.hash = data;
catch (e) {
var iframe = document.createelement ("iframe");
IFRAME.SRC = "http://www.111cn.net/proxy.html#" + data;
Document.body.appendChild (IFRAME);
}
3. The proxy page for this domain proxy.html the following code
Because all two pages are of the same domain, you can set the hash value of the main.html
Parent.parent.location.hash = Self.location.hash;
and Window.name cross-domain transmission of data is the same disadvantage, the transmission of data is a string type, if you want to pass the JSON data, the first to be converted to a string in data.html, and then in main.html in the conversion back, and the data are exposed in the URL, but also a limit is the length of the URL E can only be 2048 characters, which cannot pass too much data.