user784756
user784756

Reputation: 2373

How can I open a link in a nested iframe in the original window they're placed in?

Been trying the following from within an iframe nested in another iframe:

<a href="https://example.com" target="_parent">Link</a>
<a href="https://example.com" target="_top">Link</a>
<a href="https://example.com" target="_self">Link</a>

However, they all open in new windows instead of in the window the iframes are in. How can I make sure the link opens in the top browser window?

Upvotes: 1

Views: 722

Answers (2)

guest271314
guest271314

Reputation: 1

Try using onclick attribute

<a href="https://example.com" 
   onclick="function(e){e.preventDefault();top.location.href=this.href}">Link</a>

<iframe src="data:text/html,<!doctype html><iframe src='data:text/html,<!doctype html><a href=https://example.com onclick=function(e){e.preventDefault();top.location.href=this.href}>Link</a>'></iframe>">
</iframe>

Upvotes: 1

Anfelipe
Anfelipe

Reputation: 771

If you want that every link in the child page can be opened in the web page that hosts the iframe, then you could add this tag inside the child page:

<base target="_top" />

Upvotes: 1

Related Questions