Open In App

How to load a hyperlink from one iframe to another iframe ?

HTML Iframe or inline frame allows embedment of multiple HTML pages in an HTML page. In this article, we will see how to change the content of one iframe using hyperlinks in another iframe. 

This can be achieved by the proper usage of the name attribute in the iframe tag and the target attribute in the anchor tag. The name attribute allows each inline frame to have its own unique name while the target attribute tells the hyperlinks, where the page has to be opened when the link is clicked. Our problem will be solved if we keep the value of the target as the name of the destination iframe where the hyperlink contents should be displayed.



Example: The HTML document will embed two iframes inside it.




<!DOCTYPE html>
<html>
  <body>
    <center>
      <h2>Hello world!!</h2>
      <br />
      <iframe src="iframe1.html" 
              name="iframe1" 
              width="70%" 
              height="250">
      </iframe>
      <br /><br />
      <iframe src="" 
              name="iframe2" 
              width="70%" height="300">
      </iframe>
    </center>
  </body>
</html>

The following code is the content for “iframe1.html” used in the above code.






<!DOCTYPE html>
<html>
  <body>
    <center>
      <h1 style="color: green">GeeksforGeeks</h1>
  
      <p>
        <a href=
          target="iframe2">GfG Logo</a>
      </p>
  
      <p>
        <a href=
          target="iframe2">GfG Logo 2</a>
      </p>
  
      <p>
        <a href=
          GfG youtube video
        </a>
      </p>
  
      <p>click the above links to see changes in the frame below</p>
    </center>
  </body>
</html>

Output: This page will contain hyperlinks, each targeting the second iframe.

iframe to another iframe


Article Tags :