注册 登录
编程论坛 JavaScript论坛

怎样用js禁止"shift"键的功能?

gu_tong2008 发布于 2010-12-09 11:45, 2079 次点击
请看我的一个例子:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
</head>

<body>

<a href="http://www. target="_top">aa</a>

</body>
</html>

本来target="_top"属性是点击aa的时候,会在当前窗口链接到相应的地址,当我按住shift键并用鼠标点击aa的时候,却会弹出一个新窗口链接到相应的地址,此时如何让这个"shift"键失效呢?就是按住"shift"键跟不按住"shift"键可以达到相应的效果?
3 回复
#2
hugeannex2010-12-09 12:37
这是浏览器的功能,js无能为力。
解决的办法倒是有,就是不用a链接,而是用js打开页面,那知道按shift都不起作用了。
#3
sclorg2010-12-09 14:00
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
</head>

<body>

<a href="http://www. target="_top" onclick="window.location = this.href; return false;">aa</a>

</body>
</html>
#4
gu_tong20082010-12-09 14:11
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>

</head>

<body>

<a href="http://www. target="_top" onclick='with(event)return(!shiftKey||srcElement.tagName!="A")'>aa</a>

</body>
</html>

上面的代码当按住"shift"键的时候可以实现在IE里不弹出新窗口,也不链接的功能,但在firefox还是可以链接到http://www.,有没有办法让它们兼容呢?即在firefox浏览的时候,当按住shift键,不会链接到新地址。
1