1

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?

MrTux
  • 32,350
  • 30
  • 109
  • 146
user784756
  • 2,363
  • 4
  • 28
  • 44

2 Answers2

1

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" />
Anfelipe
  • 712
  • 10
  • 20
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>
guest271314
  • 1
  • 15
  • 104
  • 177