Home >Web Front-end >JS Tutorial >How to Redirect the Parent Window from an Iframe using JavaScript?

How to Redirect the Parent Window from an Iframe using JavaScript?

Linda Hamilton
Linda HamiltonOriginal
2024-10-30 20:51:30933browse

How to Redirect the Parent Window from an Iframe using JavaScript?

Redirecting Parent Window from an Iframe

If you want to redirect the parent window from within an iframe, you can achieve this using JavaScript. Here's how:

Window.top.location.href

To redirect the topmost parent iframe, use the following code:

window.top.location.href = "http://www.example.com";

Window.parent.location.href

To redirect the direct parent iframe, use this code instead:

window.parent.location.href = "http://www.example.com";

These JavaScript snippets effectively redirect the parent window from an iframe action, allowing you to control the navigation of the parent window from within the child iframe.

The above is the detailed content of How to Redirect the Parent Window from an Iframe using JavaScript?. For more information, please follow other related articles on the PHP Chinese website!

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