How to Open a Link From <iframe> in the Parent Window

Iframes are embedded into web pages. You can embed an <iframe> in a page, which is inside another <iframe> on another web page.

Solution with the HTML <base> tag

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.

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <base href="https://www.w3docs.com/" target="_parent">
  </head>
  <body>
    <iframe src="https://www.w3docs.com" width="500" height="500"></iframe>
  </body>
</html>

Now, you can compare the example above with the following one, where the target attribute is set to _blank, which loads the link in a new window.

<!DOCTYPE html>
<html>
  <head>
    <title>Title of the document</title>
    <base href="https://www.w3docs.com/" target="_blank">
  </head>
  <body>
    <iframe src="https://www.w3docs.com" width="500" height="500"></iframe>
  </body>
</html>
Do you find this helpful?

Related articles