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.
parent. location. href = "http://www.example.com"; Will redirect the parent 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.
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.
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.
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.
I found that <a href="..." target="_top">link</a>
works too
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With