大多是在导航栏中用到的,在导航栏中在主页和在其他的网页点击导航栏中的主页是不同的,主要就是判断这个。
我是在ascs页面中写的。
下面先看标签:
<a href="http://www.gkxx.com/" target="_blank" id="aaa" onclink="blank(id)">< span>首页 </span></ a>
JS代码:
<
script
>
function
blank(tit) {
var
text = window.location.pathname;
if
(text ==
"/index.aspx"
) {
var
el = document.getElementById(tit); //指定是哪个标签
el.setAttribute(
"target"
,
""
);
}
else
{
var
el = document.getElementById(tit);
el.setAttribute(
"target"
,
"_blank"
);
}
}
</
script
>