While these answers are good, IMHO I don't think they fully address the question.
The target attribute in an anchor tag tells the browser the target of the destination of the anchor. They were initially created in order to manipulate and direct anchors to the frame system of document. This was well before CSS came to the aid of HTML developers.
While target="_self"
is default by browser and the most common target is target="_blank"
which opens the anchor in a new window(which has been redirected to tabs by browser settings usually). The "_parent"
, "_top"
and framename
tags are left a mystery to those that aren't familiar with the days of iframe site building as the trend.
target="_self"
This opens an anchor in the same frame. What is confusing is that because we generally don't write in frames anymore (and the frame
and frameset
tags are obsolete in HTML5) people assume this a same window function. Instead if this anchor was nested in frames it would open in a sandbox mode of sorts, meaning only in that frame.
target="_parent"
Will open the in the next level up of a frame if they were nested to inside one another
target="_top"
This breaks outside of all the frames it is nested in and opens the link as top document in the browser window.
target="framename
This was originally deprecated but brought back in HTML5. This will target the exact frame in question. While the name
was the proper method that method has been replaced with using the id
identifying tag.
<!--Example:-->
<html>
<head>
</head>
<body>
<iframe src="url1" name="A"><p> This my first iframe</p></iframe>
<iframe src="url2" name="B"><p> This my second iframe</p></iframe>
<iframe src="url3" name="C"><p> This my third iframe</p></iframe>
<a href="url4" target="B"></a>
</body>
</html>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…