Name is a global property of window, including ie6,7, which is supported by almost all browsers.
Using Window.name to transfer data across domains is a feature of its use: Window.name has been saved even though the refresh, url jump
The implementation principle is very simple, the homepage uses the IFRAME to load the Outland data page, the Outland page sets this iframe the Window.name value. After loading, the IFRAME jumps back to the blank page of the domain, this time the main page can use Iframe.contentWindow.name to take the value.
Three pages: 111cn.net/main.html (Home page), 111cn.net/blank.html (blank page), b.com/data.html (Data page in Outland)
1. The data.html code for the data page in Outland is very simple, pass the data to Window.name, code as follows
<script type= "Text/javascript" >
Window.name = ' Holle world ';
</script>
2. The homepage of this domain main.html, listens to the onload event of the IFRAME, after loading the data page of the Outland, points to the local blank.html, then obtains the data, the code is as follows:
var state = 0;
var iframe = document.createelement ("iframe");
IFRAME.SRC = "http://www.b.com/data.html";
if (window. VBArray) {
Iframe.onreadystatechange = function () {
if (iframe.readystate = = ' Compltete ') {
if (state = = 1) {
var data = Iframe.contentWindow.name; You can get the data at this point.
} else {
state = 1;
IFRAME.SRC = "http://www.111cn.net/blank.html";
}
}
}
} else {
Iframe.onload = function () {
if (state = = 1) {
var data = Iframe.contentWindow.name; You can get the data at this point.
} else {
state = 1;
IFRAME.SRC = "http://www.111cn.net/blank.html";
}
}
}
Document.body.appendChild (IFRAME);
The last thing to note is that Window.name can only store data in string format, and if, window.name=1, it is automatically converted to the string "1"