Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 697
Ali Avatar asked Feb 24 '09 06:02

Ali


People also ask

How do I redirect a parent page in iframe?

parent. location. href = "http://www.example.com"; Will redirect the parent iframe.

How can I change parent URL in iframe?

1) click on images link in iframe changes Parent page, click on another iframe image link changes Parent to another page (see below). can you please post the code you're currently using, in addition to the link you provided? You need to name the parent and use the target attribute.

Does iframe support redirect?

Redirect the page containing your iframe embed The second option would be to redirect the page where you have your iframe embedded, known as the "parent" page. Modern browsers will prevent an iframe from changing the location of its parent page for security reasons.

Can iframe access parents?

When a page is running inside of an iframe, the parent object is different than the window object. You can still access parent from within an iframe even though you can't access anything useful on it. This code will never cause an error even when crossing origins.


2 Answers

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.

like image 114
MIP Avatar answered Oct 19 '22 05:10

MIP


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

like image 36
Ali Avatar answered Oct 19 '22 05:10

Ali