Reputation: 2373
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
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
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