Problem
To redirect a parent window from an iframe, what JavaScript do I need to use?
yperlink that would redirect the parent window to a new URL using JavaScript or any other means.
Asked by Ali
Solution #1
window.top.location.href = "http://www.example.com";
The top-most parent Iframe will be redirected.
window.parent.location.href = "http://www.example.com";
The parent iframe will be redirected.
Answered by MIP
Solution #2
I discovered that a href=”…” target=” top”>link/a> works well as well.
Answered by Ali
Solution #3
window.top.location.href = "http://example.com";
The window object of the page at the top of the frames hierarchy is referred to as window.top.
Answered by Luca Matteis
Solution #4
For me, target=” parent” worked perfectly. Simple and hassle-free!
Answered by rDroid
Solution #5
Alternatively, consider the following: (using document object)
parent.document.location.href = "http://example.com";
Answered by Real Red.
Post is based on https://stackoverflow.com/questions/580669/redirect-parent-window-from-an-iframe-action