关于base target="_self" 等

<base target=_blank>是将基本链接的目标框架都改为新页打开,如果对HTML、CSS和JS不是很熟悉,不建议使用这种方法,改为独立控制。
  其实<a>、<form>等很多标签都支持target="black"的属性,建议在这样的标签里单独做设置,比如:
<a href="xxx.htm" target="_blank">超链接内容</a> 
<form action="xxx.htm" target="_blank">
         表达内容
       <input type="submit" value="提交按钮">
 </form>
如果不加这一句,默认均为本页刷新,即target="_self"。
 在网页中,经常碰到这种情况:点击某些链接,就会弹出新窗口,原来的页面部改变,而有些链接,就在原窗口上打开新的链接,原窗口没有了,被覆盖了。这个是为什么呢?怎么实现的呢?
        target=_blank,这个标签,就是解决这个问题的。<base target=_blank>是将基本链接的目标框架都改为新页打开,即弹出新窗口。<a>、<form>等很多标签都支持target="black"的属性,可以在这样的标签里单独做设置,比如:
<a href="xxx.htm" target="_blank">超链接内容</a>
<form action="xxx.htm" target="_blank">
         表达内容
<input type="submit" value="提交按钮">
</form>
如果不加这一句,默认均为本页刷新,即target="_self"。还有两个这样的标签,<target=_top>表示在整页窗口打开,<target=_parent>表示在父窗口打开。
<a href="http://www.try0212.blog.sohu.com/" target="_blank">单独定义,新窗口打开</a>
<a href="http://www.try0212.blog.sohu.com/" target="_self">单独定义,相同窗口打开</a>
<a href="http://www.try0212.blog.sohu.com/" target="_top">单独定义,整页窗口打开</a>
<a href="http://www.try0212.blog.sohu.com/" target="_parent">单独定义,父窗口打开</a>
另外,这只是单独设置,如果有在某个页面上有很多的链接或者form表单,逐一的添加标签会很麻烦,有没有类似批处理的呢?
这就要用到<base target=_xxx> ,这是基本的HTML语言。用<base target=_××>来设置这个网页所有链接的目标窗口。也就是说,网页中只要添加<base target=_××>这句,那么所有的超链接就无须单独设置。最好将这句写在<head>和</head>之间。例如
<base target=_blank>表示网页中所有的超链接的目标地址都在新建窗口中打开。
<base target=_self>表示网页中所有的超链接的目标地址都在原窗口上打开。
当然,这样的标签有时也会碰到麻烦。
1 不符合标准 
当我们使用W3C过渡型标准时,即DOCTYPE(xh tml1-transitional. dtd),没有问题,但是使用严格的标准时,即DOCTYPE(xhtml1-strict.dtd),就会出错,错误提示:
"there is no attribute target for this element(in this HTML version)"
原因是,外国人认为,不经过用户同意,就随便打开新窗口,是不礼貌的,不尊重用户的,可参看 http://bbs.chinahtml.com/showthread.php?t=53657
那碰到这种情况时怎么办呢?
HTML4.0增加了一个新属性:rel,这个属性用来说明链接和包含此链接页面的关系,以及链接打开的目 标。rel有许多的属性值,比如next、previous,、chapter、section等等。我们要使用的就是rel="externa l"属性。原来这样写的代码:
<a href="document.html" target="_blank"> 打开一个新窗口</a> 现在要写成这样:
<a href="document.html" rel="external">打开一个 新窗口</a> 这是符合strict标准的方法。当然还必须配合一个javascript才有效。
javascript
完整的代码JS如下:
function externallinks() 
if (!document.getElementsByTagName) return
var anchors = document.getElementsByTagName("a"); 
for (var i=0; i<anchors.length; i++
var anchor = anchors; 
if (anchor.getAttribute("href"&& 
anchor.getAttribute(
"rel"== "external"
anchor.target 
= "_blank"
}
 
}
 
window.onload 
= externallinks; 
你可以把它保存成一个.js文件(比如external.js),然后通过外部联接方法调用:
<script type="text/javascript" src="external.js"></script> 就是这样。
2 浏览器不支持
有时,使用了上述标签,但是,任旧不见效果,比如使用了target=_blank,却不能弹出窗口,这是因为,有些浏览器被用户设置了,不让弹出窗口,当然这样设置是为了屏蔽广告,因此,这是就无法打开新窗口,知道了原因,解决就很简单了,在浏览器中设置一下就可以了。

posted on 2009-07-10 09:18 hobo 阅读(4775) 评论(14)  编辑 收藏 引用 所属分类: web

评论

# re: 关于等 2009-07-10 10:03 戴尔笔记本

不错哦  回复  更多评论   

# re: 关于base target="_self" 等 2010-01-12 11:47 ss

打开新窗体同时,怎样关闭旧窗体呢?  回复  更多评论   

# re: 关于base target="_self" 等 2010-04-03 23:37 ScottNatasha

Have no a lot of cash to buy a house? Don't worry, because it's possible to take the <a href="http://lowest-rate-loans.com">loan</a> to work out all the problems. Hence take a car loan to buy everything you need.   回复  更多评论   

# re: 关于base target="_self" 等 2010-04-16 08:53 resume writing

Yeah decidedly very
friendly for the students it was pleasant to read about this good post! If you need to get a great job firstofall you need resume writing. Study and don't forget - if you have to work and study at the same time, there arehotshots who are ready to aid you with your resume when you under time encumbrance and looking for a great job.  回复  更多评论   

# re: 关于base target="_self" 等 2012-07-14 12:47 buy essays now

It is necessary to pass all the ezaminations during the study at school. When students do not have enough time for that, the may simply buy an essay paper written by skilled writers.Click here "primewritings.com". The top solution for getting high marks is to use the PrimeWritings.company’s nice custom essays writing assistance.   回复  更多评论   

# re: 关于base target="_self" 等 2012-07-14 13:00 paper writing service

Everyone wants to get assurances that the customized research papers they get from the custom paper writing services are of good quality. Therefore, it is essential issue.   回复  更多评论   

只有注册用户登录后才能发表评论。
<2008年5月>
27282930123
45678910
11121314151617
18192021222324
25262728293031
1234567

导航

统计

常用链接

留言簿(1)

随笔分类

随笔档案

文章分类

文章档案

相册

友情连接

搜索

最新评论

阅读排行榜

评论排行榜