Skip to content
Related Articles

Related Articles

Improve Article

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

  • Difficulty Level : Easy
  • Last Updated : 25 Jul, 2021
Geek Week

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.

  • We will create an HTML page consisting of two iframes.
  • Give each iframe a unique name.
  • Create another HTML page with multiple hyperlinks in it.
  • Add the name of the second iframe in the target attribute of every hyperlink.
  • Click the links in the first iframe, and you should see the pages opening in the second iframe.

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

index.html




<!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.



iframe1.html




<!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

Attention reader! Don’t stop learning now. Get hold of all the important HTML concepts with the Web Design for Beginners | HTML  course.




My Personal Notes arrow_drop_up