JS error: permission denied to access property ‘document’— document.domain -The same source strategy of JavaScript

The reason for the error is that the domain name of the parent window and the child window are different, even under the same site, also need to write the full reference address: as under xxx.com page < iframe id=”iframe_xxxx” name=”iframe_xxxx” src =”/sub.html” frameborder=”0″ height=”300″ width=”1000″> < /iframe> With & lt; iframe id=”iframe_xxxx” name=”iframe_xxxx” src =”http://www.xxx.com/sub.html” frameborder=”0″ height=”300″ width=”1000″> < /iframe> There is a difference between
For the third party integration, the author used & LT; iframe> , through the js of the child page to adjust the elements of the parent page, there will be access to the situation. The reason for this problem is that js does not belong to the same domain, so it is forbidden to access due to the security problem of some browsers.
resources: https://developer.mozilla.org/Cn/JavaScript the same-origin policy (such as can not access, HTTP) instead of HTTPS for

File: http://sub.xxx.com/index.html

& lt; ! doctype html>
< html>
< head>

< /head>
< body>

& lt; iframe id=”iframe_xxxx” name=”iframe_xxxx” src =”http://www.xxx.com/sub.html” frameborder=”0″ height=”300″ width=”1000″> < /iframe>
< /body>
< /html>
 
File: http://www.xxx.com/sub.html

& lt; ! doctype html>
< html>
< head>
< script type=”text/javascript”>
// set domain information
document.domain = ‘xxx.com’;
// set domain information
document.domain = ‘xxx.com’;
// set the iframe height of the parent page to reference itself
function setHeight(){
//
if(window.top! = window. Self) {
the parent. The document. The getElementById (‘ iframe_xxxx). Height = document. The body. The scrollHeight + 20
}

} & lt; /script>
< /head>
< Body &western nl &western AD = “setHeight ();” >

< /body>
< /html>

= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =

the problem is caused by the browser’s security mechanism,
but it is under the same domain subdomain and secondary subdomain difference, can be solved.
the solution is to change the domain information of the two pages to be the same.
because the default page’s domain information contains the second-level domain, this setting allows the use of the top-level domain as the domain information.
< script type=”text/javascript”>
document.domain = ‘xxx.com’;
< /script>
 

Note: This method is not feasible if two pages do not belong to the same domain name. Forced setting js will report an error. Addition: if we are not sure whether the referenced page is in the same domain as the referenced page, we can determine this by obtaining the url address of the referenced page
< script type=”text/javascript”>
//document.referrer – returns the URL of the document that was loaded with the current document.
$p_url = document.referrer;
< /script>
//= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Reference: http://hi.baidu.com/eecc00/item/7c99477420e9f1345c1789e3


Read More: