Home >Web Front-end >JS Tutorial >How can I redirect the parent window from within an iframe using JavaScript?

How can I redirect the parent window from within an iframe using JavaScript?

DDD
DDDOriginal
2024-10-26 19:48:031023browse

How can I redirect the parent window from within an iframe using JavaScript?

Redirecting Parent Window from an Iframe

Question: How can I redirect the parent window from within an iframe using JavaScript?

Answer: To redirect the parent window from an iframe, you can utilize the following JavaScript code:

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

This code will redirect the top-most parent iframe to the specified URL.

If you need to redirect the immediate parent iframe, use this code instead:

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

These scripts will allow you to seamlessly navigate the parent window from within an iframe.

The above is the detailed content of How can I redirect the parent window from within 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