Search code examples
javascriptiframedhtml

Redirect parent window from an iframe action


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.


Solution

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

    Will redirect the top most parent Iframe.

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

    Will redirect the parent iframe.