Page A: page B, can you send me a data?
Page B: Well, we are not in the same domain because of the web security issue, so the browser prohibits me from transmitting data directly to you.
Page A: Is there any way to solve this problem?
Page B: You can use Window.name.
Page A: What do you need me to do?
Page b:1. You first create an IFRAME node dynamically;
2. Set node properties src point me;
3. I will set window.name = ' B ';
4. Then you re-set the properties of the node iframe src Point and you are in the same domain under the sibling page C;
5. Although the value of the attribute src is changed, the value of window.name does not change, or B, so you can get data b directly from page C.
Page A: See, this becomes the same domain access from cross-domain access.
Page B: Yes. Yes, the page C here does not have the actual content, just play a role of the bridge Oh.
<!--page a--><script> var state = 0; IFR = document.createelement (' iframe '); IFR.SRC = ' http://b.com/b.html '; if (ifr.attachevent) { ifr.attachevent (' onload ', LOADFN); } else { ifr.onload = LOADFN; } function Loadfn () { if (state = = = 1) { var data = Ifr.contentWindow.name; alert (data); } else if (state = = = 0) {state = 1; Ifr.contentWindow.location = "http://a.com/c.html"; } }; Document.body.appendChild (IFR); </script>
<!--page B--><script>window.name = ' B ';</script>
Framework elements-cross-domain access-window.name