Framework elements-cross-domain access-window.name

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.