A new feature of Google's browser -- getting the parent object of iframe

Source: Internet
Author: User

Google Chrome is very convenient in debugging JavaScript scripts. Today, when using Google Chrome to debug code, I accidentally found a strange problem: blocked a frame with origin "null" from accessing a frame with origin "null ". protocols, domains, and ports must match ., this is mainly because the parent of the page where the iframe is located is not obtained. The Code is as follows:

Index.html:

<Html>

<Head>

<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>

<Script type = "text/javascript">

Function test (){

Alert ('you have successfully called the function on the page where the iframe tag is located! ');

}

</Script>

</Head>

<Body>

<Iframe frameborder = "1" srcw.'child.html 'style = "width: 50%; height: 50%;"> </iframe>

<Div style = "font-size: 36px; margin-left: 40%; color: red;"> iframe tag page </div>

</Body>

</Html>

Child.html:

<Html>

<Head>

<Meta http-equiv = "Content-Type" content = "text/html; charset = gb2312"/>

</Head>

<Body>

<Input type = "button" onclick = "javascript: window. parent. test ();" value = "Call the function on the page where the iframe tag is located"/>

<Div style = "font-size: 21px; margin-left: 40%; color: red;"> pages referenced by the iframe tag </div>

</Body>

</Html>

[Download code file]

If the above Code runs directly on the computer using Google Chrome, the above error "Blocked a frame with origin" null "from accessing a frame with origin" null "will occur ". this is not the case for Protocols, domains, and ports must tables files.

Summary: if you use the file protocol locally to open a page containing the iframe tag in Google browser, the page referenced by the iframe tag cannot access the parent object on the page where the iframe tag is located, unless published on a server (such as Tomcat.

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.