日期:2014-05-17  浏览次数:20594 次

html中<a>标签_top和_parent的区别

源:http://blog.sina.com.cn/s/blog_698e6e270100m3a0.html

评:

在html中,<a>标签有个target属性,而targe属性有四个值,分别是:_blank、_self、_top、 _parent。前两个相信很好理解,第一个就是在新窗口中打开的意思,第二个时候默认的,就是在当前窗口打开,那下面来说下后两者的区别。

??? _top就是打开的页面占据了整个页面,_parent就是打开的页面只是在父页面中打开,现在可能有点不太好理解,这两个属性主要用于框架文件中,首先我先贴上我的html文件,如下,注:代码中红色的字体在最后有讲解:

?源:http://www.taoshaw.com/taoshaw/article.asp?id=1868

在手动改HTML代码时经常会用到target参数,常用的有两个target=_blank 和target=_self意思为:
target=_blank表示在新窗口中打开该链接;
target=_self表示相同框架,即在当前窗口(或当前选项卡)中打开该链接
还有两个不常用的:
target=_parent,将链接的文件载入含有该链接框架的父框架集或父窗口中。如果含有该链接的框架不是嵌套的,则在浏览器全屏窗口中载入链接的文件,就象_self参数一样。
target=_top,在当前的整个浏览器窗口中打开所链接的文档,因而会删除所有框架
不写的话就是表示默认值,默认值一般跟浏览器有关。

比如网A中镶嵌iframe了网页B,网页B又镶嵌iframe了网页C

:如果网页C中连接设置target=_parent,则跳将网页B去掉直接A中嵌入网页C中链接页面;
而如果网页C中target=_top ,则直接跳出所有iframe框架,直接转向C中链接页面。

?

?

main.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<frameset rows="20%,*">
?<frame src="top.html" noresize="noresize" />
?<frame src="bottom.html" name="bottom"?noresize="noresize" />
</frameset>
</html>

?

top.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body style="font-size:24px;font-weight:bold;">
Example of "_parent" and "_top"
</body>
</html>

?

bottom.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<frameset cols="20%,*">
?<frame src="left.html" noresize="noresize" />
?<frame src="right.html" noresize="noresize" />
</frameset>
</html>

left.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body style="font-size:18px;font-weight:bold;">
I'm left in bottom!!
</body>
</html>

?

right.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; c