HTML

What is the difference between _top and _parent target attribute of <a> Tag in HTML

Ravindra Kumar

What is the difference between _top and _parent target attribute of <a> Tag in HTML

Answer

_top : If you are using nested frame then it goes to the first / top windows

_parent : If you are using nested frame then it goes to the parent / above windows on which you clicked the link

Example:

This example is based on iframe

Let’s suppose you have three web pages:

  • hyperlink.html
  • frame1.html
  • frame2.html
  • frame3.html

 

On First file hyperlink.html, You need to put 2 frames which are following.

 

hyperlink.html Source Code

<html>
   <head>
   </head>
   <body>

           <iframe src="frame2.html" name="B"><p> This my second iframe</p></iframe>
           <iframe src="frame3.html" name="C"><p> This my third iframe</p></iframe>

   </body>
</html>

This file has 2 frames, first showing frame2.html and 2nd is showing frame3.html

frame1.html Source Code

<html>
     <head>
     </head>
     <body>
         <b>Frame 1</b>
         <a target="_parent" href="https://ravindra24.com/">link</a>
     </body>
</html>

frame2.html Source Code
This file has 1 frame that is showing frame1.html

<html>
          <head>
          </head>
          <body>
                   <b>Frame 2</b>
                   <a target="_self" href="frame3.html">link</a><br/>
                   <iframe src="frame1.html" name="A"><p> This my first iframe</p></iframe>

          </body>
</html>

frame3.html Source Code
This file has 1 frame that is showing frame4.html

<html>
              <head>
              </head>
              <body>
                           <b>Frame 3</b>
                            <a target="_parent" href="https://ravindra24.com/">link</a><br/>
                            <iframe src="frame4.html" name="B"><p> This my second iframe</p></iframe>
              </body>
</html>

frame4.html Source Code

<html>
                 <head>
                 </head>
                 <body>
                            <b>Frame 4</b>
                            <a target="_top" href="https://ravindra24.com/">link</a><br/>
                 </body>
</html>

 

This file has 2 frames and first frame shows frame2.html and this frame.html show showing 1 frame that is showing frame1.html that has _parent value of target attribute which is following.

<a target="_parent" href="https://ravindra24.com/">link</a> 

When you click this link, it opens the website in parent window

Now, 2nd frame of hyperlink.html is showing frame3.html that is showing a frame which showing frame4.html that has following link.

<a target="_top" href="https://ravindra24.com/">link</a>

When you click this link, it opens the website in main window.

So I think you might be getting the differences.

Ravindra Kumar

Ravindra is a passionate full stack developer and dedicated blogger with a flair for crafting user-friendly web applications and insightful articles. With expertise spanning front-end and back-end technologies, Ravindra brings ideas to life through innovative coding solutions.

Suggested Reading

How to Create Image Maps in HTML ?

Creating image link in HTML, Learn how to give multiple links in single image in HTML Suppose, You want to give a clickable link to specific part of a image that can be possible by <map> tag of HTML.You can also target multiple clickable links to a particular are of the image.so here you need […]

How to Design Stylish Forms in HTML

In this post, i am going to explain that how can we design a stylish HTML form for our website and this form will be good looking.I am going to use HTML,CSS, Jquery and bootstrape in this example. First, You need to have a index.html file to design the input fields and i am going […]

How to designing responsive Navigation bar using HTML and CSS

Every website needs Navigation bar to navigate on the website properly and this is very usefull for users as well.If a website does not have good navigation interface, users prefer to leave this type of website immediately. index.html <!DOCTYPE html> <html lang="en"> <head> <title>Menu Tutorial</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="style.css"/> <link […]

What is initial-scale=1.0

The initial-scale=1.0 is a setting used within the HTML <meta> viewport tag. It controls the initial zoom level of a webpage when it’s first loaded on a mobile device or a responsive screen. <meta name=”viewport” content=”width=device-width, initial-scale=1.0″> Meaning of initial-scale=1.0: initial-scale=1.0 sets the zoom level to 100% when the page first loads. A value of […]

How to make sticky header using HTML and CSS

Creating a sticky header using HTML and CSS is straightforward. A sticky header remains visible at the top of the viewport as the user scrolls down the page. You can achieve this using the position: sticky property in CSS. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Sticky Header</title> <link rel="stylesheet" href="styles.css"> […]

How to short html Table | Shorting a Table by Ascending or Descending Order in HTML

Learn how to short HTML Table | Shorting a Table by Ascending or Descending Order in HTML Sorted data help the user to understand the data better, If this data is too large in rows and columns, this is necessary to keep the data sorted. In HTML you can short tables by using Javascript so […]