运行代码 缩小
汉王
HTML代码
复制 格式化 注释 注释 清空
放大
AخA
 
1
<html>
2
<head>
3
<title>接收键盘指令的脚本</title>
4
</head>
5
<body>
6
按A就会跳转到娃娃亲的网页,请按A
7
<SCRIPT language="JavaScript">
8
<!--
9
var hotkey=97
10
var destination="http://www.csdn.net"
11
if (document.layers)
12
document.captureEvents(Event.KEYPRESS)
13
function backhome(e){
14
if (document.layers){
15
if (e.which==hotkey)
16
window.location=destination
17
}
18
else if (document.all){
19
if (event.keyCode==hotkey)
20
window.location=destination
21
}
22
}
23
document.onkeypress=backhome
24
onkeydown="javascript:onenter();"
25
function onenter(){
26
 if(event.keyCode==13){
27
alert("回车");
28
}
29
}
30
</SCRIPT>
31
</bdoy>
32
</html>
CSS代码
复制 格式化 注释 注释 颜色 清空
放大
CSS代码...
x
 
1
JS代码
复制 格式化 注释 注释 清空
放大
JS代码...
xxxxxxxxxx
1
 
1
名称
网页响应键盘按钮跳转到指定网址,JavaScript代码
分类
网站常用
描述
一段JavaScript代码,主要于浏览器配合实现 网址跳转的功能,不过这里的网址需要击打键盘按键后才生效,也就是说要让Javscript接收键盘指令,最终实现网址转向。在这段代码中,网址和指定键是可以修改的。
收藏