Given the following HTML, is it possible for the anchor tag in the iframe to target the parent window?
<div>
<iframe src="/pageview.html"></iframe>
</div>
iframe (pageview.html) content :
<a href="http://www.google.com">link</a>
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.
Sending some data from the child iframe to the parent window is also pretty simple. Whenever you embed an iframe, the iframe will have a reference to the parent window. You just need to use the PostMessage API to send data via the window. parent reference of the parent window.
All you have to do is first dispatch an event from the iframe to the parent that notifies the parent that the iframe is loaded (essentially a "ready message"). The parent will be listening for messages and if it receives the "ready message" event, it can then reply to the iframe with whatever message you want to send.
You can embed an iframe in a page that is inside another iframe on another web page. When you set the target attribute to _parent, the link will open in the web page that is holding the iframe. In most situations with iframes, this target will open links in the same way that the _parent target does.
You want the target
attribute:
<a href="something" target="_parent">go</a>
Using _parent
will target the frame's immediate parent window. To target the top window, use _top
.
<div>
<iframe src="/pageview.html">
<a onclick="javascript:window.parent.location.href='http://www.google.com'; return false;">link</a>
</iframe>
</div>
Should be something like that...
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