Data transfer between different web domains

Source: Internet
Author: User

During Development today, you need to call an address from another department. The demo sent is

VaR userinarray = []; <br/> // userinarray. push ("ff8080812316698012398ea851b006b # Gao Jie #2"); <br/> var useroutarray = []; <br/> function test () {<br/> document. domain = "remote.net"; <br/> useroutarray = Window. showmodaldialog ("http://xxx.kk.yy.htm", userinarray, "dialogwidth = 753px; dialogheight = 505px"); <br/>}</P> <p> function Test2 () {<br/> alert (useroutarray [0]); <br/>}

 

The key is in document. domain = "remote.net"; this allows me to access his page. After modifying the page according to this demo, I click Save. No response is returned. The JS error message "no permission" is displayed ", I checked it online and found it was caused by this domain. At this time, I wanted to use js to change the domain back, but all of them were prompted with an error. I checked it online:

  • The document. Domain attribute cannot be set at will. It can only be set as the upper-level domain of the file's domain. For example, if imgupload.html belongs to img.mycompany.com, its document. Domain attribute can be set to "mycompany.com", but not "IMG. mycompany" or others, such as "foo.com ".
  • Only when the two domains have the same upper-level domain can the data exchange between them be realized by specifying document. domain, and the document. Domain attribute must be set as the public domain of the two. For example, if newsedit.html belongs to news.mycompany.com and imgupload.html belongs to img.yourcompany.com, no matter how you set document. domain cannot exchange data between them. For example, if imgupload.html belongs to img.mycompany.com, we can set the document of the two pages. the domain attribute is set to "mycompany.com", but cannot be set to "IMG. "mycompany" or other domains, such as "foo.com ".
  • I found that this call is useless. I should not change the domain on my homepage, or I cannot change it back. After a long time, I finally got it ready. The homepage was not moving, and the Code was changed

    VaR userinarray = []; <br/> // userinarray. push ("ff8080812316698012398ea851b006b # Gao Jie #2"); <br/> var useroutarray = []; <br/> function test () {useroutarray = Window. showmodaldialog ("myurl. JSP ", userinarray," dialogwidth = 753px; dialogheight = 505px "); <br/>}</P> <p> function Test2 () {<br/> alert (useroutarray [0]); <br/>}

    Note that you do not need to set the domain here, and then point the address to your own page to make a post on your own page.

    Then myurl. JSP code

    <HTML> <br/> <pead> <br/> <MCE: Script Type = "text/JavaScript"> <! -- <Br/> userinarray = Window. dialogarguments; <br/> document. domain = "remote.net"; // todo: <br/> function userselect (users) {// callback <br/> self. returnvalue = users; <br/> self. close (); <br/>}< br/> // --> </MCE: SCRIPT> <br/> </pead> <br/> <body> <br/> <! -- // Todo: --> <br/> <IFRAME id = "some" src = "http://xxx.kk.yy.htm" scrolling = "no" frameborder = "0" width = "753" Height = "505"> </P> <p> </iframe> <br/> </body> <br/> </ptml>

     

    Of course, the remote call has also been transformed, and the userselect Method on this page will be called back. This method will return data.

     

     

     

     

     

    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.