Redirecting Parent Window from an iFrame
In the presence of an iFrame embedded within a parent window, the need may arise to redirect the parent window's location to a new URL. To achieve this, JavaScript offers a simple solution.
Using JavaScript to Redirect the Parent Window
Within the JavaScript code of your iFrame, you can utilize the following methods:
Redirect Top-Most Parent IFrame:
window.top.location.href = "http://www.example.com";
Redirect Parent IFrame:
window.parent.location.href = "http://www.example.com";
These code snippets will instruct the respective parent iFrame (top-most or immediate) to redirect to the specified URL.
Example HTML for IFrame with Hyperlink
Click Here to Redirect Parent IFrame
By clicking the hyperlink within the iFrame, the parent window will be redirected to the specified URL.
Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.
Copyright© 2022 湘ICP备2022001581号-3