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

chkdk
chkdk
46 Points
2 Posts

I am using iframe to show different widget page. I need to open all links of the widget pages to the parent window.

Views: 13164
Total Answered: 3
Total Marked As Answer: 0
Posted On: 26-Jun-2017 06:02

Share:   fb twitter linkedin
Answers
edx
edx
506 Points
24 Posts
         

I found the good 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 (anchor links) on the page in the parent window. If you want your links to load in a new window, use:

<base target="_blank">

This tag is fully supported in all browsers.

Posted On: 29-Jun-2017 02:00
Jak
Jak
908 Points
132 Posts
         

If you want to a particular link to open parent window use following

<a target="_parent" href="https://www.niceonecode.com">link</a>
Posted On: 29-Jun-2017 02:03
chkdk
chkdk
46 Points
2 Posts
         

With javascript, I found this:

window.parent.location.href= "https://www.google.com";
Posted On: 29-Jun-2017 02:05
 Log In to Chat