Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iframe click link it opens in parent page rather than in iframe page

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?

like image 265
001 Avatar asked Jun 15 '10 11:06

001


People also ask

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

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

How do I open a link in an iframe?

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.

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.

Can an iframe get parent URL?

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.


2 Answers

On the iFrame page:

<a href="javascript:parent.window.location.href='http://cnn.com/';">Go to CNN</a>
like image 171
Gert Grenander Avatar answered Oct 16 '22 06:10

Gert Grenander


If its an <a /> tag then set the target attribute to _parent

This will open the linked document in the parent frameset

like image 26
rahul Avatar answered Oct 16 '22 07:10

rahul