Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make all links in an iframe open in new tab [duplicate]

I'm trying to make it so when you click on a link in an <iframe> it will open the link in a new tab - not in the <iframe>. Please note I do not have control of the content the people are viewing through the <iframe>.

I'm trying to do this with javascript possibly, like $('a').setAttribute('target','_blank'); but it's not working out for me. I also have in my HTML document <base target="_blank">, that is not doing the trick too.

Is this impossible? Or am I just searching in the wrong places? Thanks in advance!

like image 356
Darryl Huffman Avatar asked Apr 02 '14 10:04

Darryl Huffman


People also ask

How do I make an iframe link open in a new tab?

How do I do this? Thanks! By adding target="_blank" to the anchor, it will open it in a new tab. By adding target="_parent" to the anchor, it will open it up in the same window like a normal link.

Can an iframe open a new window?

Yes you can open a new Window from iFrame........

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

1 Expert Answer 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.

Which link within iframe should open within the entire window?

The iframe tag is used to display a web page inside a web page. When you create a document to be inside an iframe, any links in that frame will automatically open in that same frame.


1 Answers

To load all links on the page in the parent window use:

<base target="_parent" />

else in a new window use:

<base target="_blank" />
like image 198
ronish Avatar answered Sep 18 '22 06:09

ronish