A pit of the opener property of the Window object in JS

Source: Internet
Author: User

2018-05-08 17:48:33

Today, I wrote the JS code when I ran into a small problem that I struggled for a long time, here to record as notes,

The problem is this: in my own child window, I'm using the opener property to get a window object that doesn't have a parent.

Now that the problem has been solved, please see below

This is the code for the parent window (windows.html):

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title>insert title here</title>
<body>
<input type= "button" value= "Open child Window" onclick= "Show ()"/><br/>
</body>
<script type= "Text/javascript" >
Function Show () {
window.open ("user.html", "", "height=300,width=400", "");
}
</script>

This is the code for the child window (user.html):

<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >
<meta http-equiv= "Content-type" content= "text/html; Charset=utf-8 ">
<title>insert title here</title>
<body>
<input type= "button" value= "Bounce Out" onclick= "Run ()"/><br/>
</body>
<script type= "Text/javascript" >
function Run () {
Window.opener.alert ("Pinball");
}
</script>

No accident, click on the Parent window button, will pop up the child window,

Then click on the Sub-window is a button, the parent window will appear a pop window (the pop-up window is written three characters);

But the parent window does not have the popup window to bounce out, next i in the child window presses F12 to look debugging, has the mistake to say I did not get to the parent window the reference ...

After a long struggle, I changed another browser Firefox, then succeeded.

The solution to this problem is that you can't run this code (not black chrome) with the Chrome browser, and I don't know why. Let's just ignore this.

A hole in the opener property of the Window object in

JS

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.