JS cross-domain call document.domain--the same base domain page between the calls

Source: Internet
Author: User

Cross-domain implementation with Document.domain:

Prerequisites: These two domain names must belong to the same base domain name! And the protocol used, the port must be consistent, or you can not use Document.domain cross-domain

JavaScript prohibits two or more pages of different domains from interacting with one another for security reasons.
Pages in the same domain do not have any problems when working with each other.

For example, a Web page in aaa.com (a.html) uses an IFRAME to introduce a Web page (b.html) in a bbb.com.
You can see the contents of b.html in a.html, but you can't use JavaScript to manipulate it. Because these two pages belong to a different domain, before the operation, JS will detect two pages of the domain is equal, if it is equal, allow its operation, if not equal, will reject the operation.
It is impossible to change a.html and b.html using JS to the same domain. Because their underlying domain names are not equal. (forcing JS to change them to equal fields will be reported with the same "parameter invalid error.") ")

So if you introduce another page in the aaa.com in a.html, there is no problem because the domain is equal.

In another case, two subdomains:

Aaa.xxx.com
Bbb.xxx.com

One of the pages in AAA (a.html) introduced a Web page in BBB (b.html),
At this time a.html also can not manipulate the contents of b.html inside.
Because Document.domain is not the same, one is aaa.xxx.com and the other is bbb.xxx.com.

At this point, we can change the domain of two pages into the same JavaScript,
Need to join in a.html and b.html:

Document.domain = "xxx.com";

This way the two pages will be able to manipulate each other. That is, the "cross-domain" between the same base domain is implemented.

JS cross-domain call document.domain--the same base domain page between the calls

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.