Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opening anchor tag from iframe in parent frame

Tags:

html

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>
like image 786
Wesley Avatar asked Feb 19 '13 00:02

Wesley


People also ask

How do you force a link from iframe to be open in the parent window?

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.

How do I transfer data from iframe to parent?

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.

Can parents communicate with iframe?

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.

How do you call an iframe in anchor tag?

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.


2 Answers

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.

like image 95
gilly3 Avatar answered Oct 20 '22 08:10

gilly3


<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...

like image 22
rnirnber Avatar answered Oct 20 '22 09:10

rnirnber