Home >Web Front-end >JS Tutorial >js iframe cross-domain access (same main domain/non-same main domain) are introduced in depth_javascript skills
js cross-domain is a topic that has been discussed a lot. iframe cross-domain access has also been thoroughly studied.
Generally divided into two situations:
1. Cross-domain between different sub-domains under the same main domain;
Same main domain but different sub-domains Cross-domain issues can be solved by setting the same document.domian;
The parent page can access the child page by document.getElementById("myframe").contentWindow.document to access the content of the iframe page; if contentDocument is supported, the document can also be directly accessed .getElementById("myframe").contentDocument accesses the content of the sub-page;
The sub-page accesses the parent page, and can use the parent.js global attribute
2. Cross-domain between different main domains ;
The premise is that a.html under www.a.com, the iframe in a.html calls b.html under www.b.com, and the iframe under b.html calls c.html under www.a.com
b.html is not an object that cannot directly access a.html because it involves cross-domain, but it can access parent. Similarly, the parent of c.html can access b.html. c.html and a.html are in the same domain and can access objects under a. parent.parent.js object!
Look at the following example:
a.html