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