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