Home > Web Front-end > JS Tutorial > body text

Introduction to the difference between window.parent and window.openner_Basic knowledge

WBOY
Release: 2016-05-16 17:54:31
Original
1163 people have browsed it

Today I will summarize the differences and usage of several objects in js:
First of all, let’s talk about the usage of parent.window and top.window
"window.location.href" and "location.href" are the jumps to this page
"parent.location.href" is the page jump to the previous layer
"top.location.href" is the outermost page jump
Example:
If A, B, C ,D is all jsp, D is the iframe of C, C is the iframe of B, and B is the iframe of A. If the js in D is written like this
"window.location.href", "location.href": D page jumps Go to
"parent.location.href": C page jump
"top.location.href": A page jump
Now I finally understand the usage of target when connecting:
_blank : Reopen a window
_parent: Parent window performs redirection
_self: Self page redirection
_top: First parent window redirection
In summary, it can be seen from the above: parent.window: parent Window object top.window: the object of the first parent window
Let’s focus on the difference between window.parent and window.openner
window.parent is the iframe page that calls the parent page object. When we want to embed from the iframe You can directly use window.parent to access the outer page;
The example is as follows:
A.html

Copy code The code is as follows:



Parent page




Input value:



< ;/div>




B.html
Copy code The code is as follows:






The text box value is: < /span>





window.opener is window.open or hyperlink The child page opened calls the parent page object
The example is as follows
a.html
Copy code The code is as follows:



Parent page





Input Value:




Hyperlink opens page B





b.html
Copy code The code is as follows:






The text box value is: < ;/span>




Here are a few commonly used examples:
parent.window and top.window are generally used in split pages, namely frameset or iframe.
Return to login.aspx after logging out of the entire frame: parent.window. location='Login.aspx' or
top.window.location='Login.aspx'
window.parent is also often used in the framework,
Refresh: window.parent.location.reload(); Or refresh a certain frame: window.parent.MainForm.location.reload();
Get the element value of other frames: window.parent.MainForm.form1.text1.value;
window.opener mainly gets passed Hyperlinks or window.open() open some pages of the own page, such as getting values, refreshing, etc.
Refresh: window.opener.location.reload();
Getting values: window.opener.document.getElement ("txtName").value;
Back: top.playFrame.history.go(-1);
Forward: top.playFrame.history.go(1);
Refresh: top.playFrame. location.reload();
That’s all. These objects are very useful.
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template