Home >Web Front-end >JS Tutorial >About the usage and difference of window.location.href, location.href, parent.location.href, top.location.href in js_javascript skills

About the usage and difference of window.location.href, location.href, parent.location.href, top.location.href in js_javascript skills

WBOY
WBOYOriginal
2016-05-16 18:18:121259browse

"window.location.href" and "location.href" are the jumps to this page

"parent.location.href" are the jumps to the previous page

"top.location.href "is the outermost page jump

Example:

If A, B, C, and D are all jsp, D is the iframe of C, C is the iframe of B, and B is A's iframe, if the js in D writes

"window.location.href", "location.href": D page jumps to

"parent.location.href": C page Jump

"top.location.href": Jump to page A

If there is a form in page D,

: Jump to page D after the form is submitted. Go to

: A new page pops up after the form is submitted

: Page C jumps after the form is submitted

: Page A jumps after the form is submitted Go to

Regarding page refresh, write this in D page:

"parent.location.reload();": C page refresh (of course, you can also use the opener object of the child window to obtain Object of the parent window: window.opener.document.location.reload(); )

"top.location.reload();": A page refresh
Statement:
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