window.top.location.href = "http://www.example.com";
As stated previously, will redirect the parent iframe.
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";
target="_parent" worked great for me. easy and hassle free!
@MIP is right, but with newer versions of Safari, you will need to add sandbox attribute(HTML5) to give redirect access to the iFrame. There are a few specific values that can be added with a space between them.
Reference(you will need to scroll): https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe
<iframe sandbox="allow-top-navigation" src="http://google.com/"></iframe>
This will solve the misery.
If you'd like to redirect to another domain without the user having to do anything you can use a link with the property:
as said previously, and then use:
to have it automatically redirect.
It is possible to redirect from an iframe, but not to get information from the parent.
window.parent.window.location.href = 'http://google.com'
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 :
Redirect iframe in parent window by iframe in the same parent:
window.parent.document.getElementById("content").src = "content.aspx?id=12";
©2020 All rights reserved.