Home > Web Front-end > JS Tutorial > body text

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

DDD
Release: 2024-10-26 19:48:03
Original
958 people have browsed it

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

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

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!

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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!