html中<a>标记的href属性不能正确跳转

来源:互联网 发布:51信用卡管家淘宝认证 编辑:程序博客网 时间:2024/05/16 06:30

可以正常使用的html源码:

<html>
<head>
<script language="javascript">
 function clickHandle()
 {
  try
  {
   throw new Error(0,"test");
  }
  catch(tmpE)
  {
   alert("失败"+tmpE.message);
  }
 }
 
 function open_window(){
  window.open("","","channelmode=yes,fullscreen=yes");
 }
</script>

</head>

<body>
<input type="button" value="click" onclick="clickHandle()"/>
<input type="button" value="open window" onclick="open_window()"/>
<a href="javascript:void window.open('http://www.sina.com.cn/','XX',' left=0,top=0,width='+ (screen.availWidth - 10) +',height='+ (screen.availHeight-50) +',scrollbars,resizable=yes,toolbar=no')">Open</a>
</body>
</html>

不能正确跳转的html源码

<html>
<head>
<script language="javascript">
 function clickHandle()
 {
  try
  {
   throw new Error(0,"test");
  }
  catch(tmpE)
  {
   alert("失败"+tmpE.message);
  }
 }
 
 function open_window(){
  window.open("","","channelmode=yes,fullscreen=yes");
 }
</script>
<base target="frmContent" />
</head>

<body>
<input type="button" value="click" onclick="clickHandle()"/>
<input type="button" value="open window" onclick="open_window()"/>
<a href="javascript:void window.open('http://www.sina.com.cn/','XX',' left=0,top=0,width='+ (screen.availWidth - 10) +',height='+ (screen.availHeight-50) +',scrollbars,resizable=yes,toolbar=no')">Open</a>
</body>
</html>


通过比较代码可以看到问题出在<base>标记上,如果加上,则href属性指定的代码不能被正确解释执行,去掉后则可以

HTML DOM Base 对象

Base 对象

Base 对象代表 HTML 的 base 元素。

在 HTML 文档中 <base> 每出现一次,Base 对象就会被创建。

Base 对象属性

属性描述href设置或返回针对页面中所有链接的基准 URL。id设置或返回 <base> 元素的 id。target设置或返回针对页面中所有链接的默认目标框架。

通过上面的描述可以知道,如果设置了页面的<base>的target属性,则在打开<a>的href连接时,将会在target指定的框架中打开,除非你

设置了<a>标记的target属性;

但是一般我们通过脚本在新窗口中打开连接的时候是不会再设置target属性的,而且你一旦决定用脚本打开窗口去打开连接,也不可以再用target属性了

否则、就会想<base>的target一样的效果了。


0 0
原创粉丝点击