Redirect parent window from an iframe action

Viewed 507296

What JavaScript do I need to use to redirect a parent window from an iframe?

I want them to click a hyperlink which, using JavaScript or any other method, would redirect the parent window to a new URL.

14 Answers

I found that <a href="..." target="_top">link</a> works too

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

window.top refers to the window object of the page at the top of the frames hierarchy.

or an alternative is the following (using document object)

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

For current page - window.location.href = "Your url here";

For Parent page - window.top.location.href = "Your url here";

From HTML

<a href="http://someurl" target="_top">link</a>
window.top.location.href = 'index.html';

This will redirect the main window to the index page. Thanks

We have to use window.top.location.href to redirect parent window from an iframe action.

Demo url :

Related