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
Release: 2024-10-30 20:51:30
Original
972 people have browsed it

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";
Copy after login

Window.parent.location.href

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

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

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!

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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template