Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force link from iframe to be opened in the parent window

I need to open the link in the same parent page, instead of open it in a new page.

note : The iframe and parent page are the same domain.

like image 924
Haim Evgi Avatar asked Jun 24 '09 11:06

Haim Evgi


People also ask

How do I get iframe links to open in 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 open an iframe window in separate windows?

You can do it with jquery and window. open method. JS : var iframe = $("#iframe"); var newWindow = window.

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

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 get parent URL?

location. ancestorOrigins[0] will get the parent url, but this api only works in chromium browsers (see support). this also supports nested iframes, where the bottom most child has access to the urls of each parent iframe.


2 Answers

I found the best solution was to use the base tag. Add the following to the head of the page in the iframe:

<base target="_parent"> 

This will load all links on the page in the parent window. If you want your links to load in a new window, use:

<base target="_blank"> 

Browser Support

like image 126
Chris Vasselli Avatar answered Sep 21 '22 11:09

Chris Vasselli


Use target-attribute:

<a target="_parent" href="http://url.org">link</a> 
like image 35
nnevala Avatar answered Sep 22 '22 11:09

nnevala