User clicks on URL hyperlink (http://example.com) within a iframe dialog window, dialog window closes and link is open in parent page.
how do you open the clicked link in the parent page instead of inside the iframe page?
If you are looking to just open some url in a new window, there are two ways to do it - by adding target="_blank" (click to see in action and read more) parameter to an A tag (your link), or, by using open() method of JavaScript (click to see in action and read more).
To open the link from <iframe> in the parent window, you can use the <base> tag and set the target attribute to _parent in the <head> section.
To force a single link from iframe to open in the parent window: add target="_PARENT" within that links anchor tag. To force ALL links from iframe to open in the parent window: add the base tag with target="_PARENT" in the head section of the iframe html page.
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.
On the iFrame
page:
<a href="javascript:parent.window.location.href='http://cnn.com/';">Go to CNN</a>
If its an <a />
tag then set the target
attribute to _parent
This will open the linked document in the parent frameset
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