views:

5099

answers:

4

What the title says. How can it be done? I want them to click a hyperlink which, using javascript or any other methods, would redirect the parent window to a new url.

+11  A: 
window.top.location.href = "http://site.com";

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

Luca Matteis
window.top.location.href property can't be updated from Iframe, it throws access denied execption. It can only be executed when you are testing on localhost
Ummar
+1  A: 

or an alternative is the following (using document object)

parent.document.location.href = "http://site.com";
Chandan .
+1  A: 

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

Click Upvote
+1  A: 
window.top.location.href = "http://www.site.com"; 

As stated previously, will redirect the parent iframe. One thing to bare in mind is that both the website, and the site contained in the iframe need to be in the same domain for this to work, or you'll get an access denied exception.

So, if the site is 'www.site.com', and the iframe is 'iframe.site.com', in both pages you'll need to put:

document.domain = "site.com"
MIP