做WEB热键
类别: JavaScript教程
如何让程序检测你的按键,实现WEB热键功能呢?
请看下列代码:
<html>
<head>
<script language=\'javascript\'>
<!--
function issueCommand(x){
if (document.layers)
{
if (x.which==99||x.which==67)
window.close();
else if (event.keyCode==112||event.keyCode==80)
self.print();
else if (event.keyCode==110||event.keyCode==78)
alert("Sorry, this is the only song in the List");
}
else if (document.all){
if (event.keyCode==99||event.keyCode==67)
window.close();
else if (event.keyCode==112||event.keyCode==80)
self.print();
else if (event.keyCode==110||event.keyCode==78)
alert("Sorry, this is the only song in the List");
}
}
//-->
</script>
</head>
<body>
<script language=\'javascript\'>
<!--
if (document.layers)
document.captureEvents(Event.KEYPRESS);
document.onkeypress=issueCommand
-->
</script>
<font size=6><u>P</u>ress P</font><p>
<font size=6><u>N</u>ext One</font><p>
<font size=6><u>C</u>lose Window</font><p>
</body>
</html>
是不是很简单.
请看下列代码:
<html>
<head>
<script language=\'javascript\'>
<!--
function issueCommand(x){
if (document.layers)
{
if (x.which==99||x.which==67)
window.close();
else if (event.keyCode==112||event.keyCode==80)
self.print();
else if (event.keyCode==110||event.keyCode==78)
alert("Sorry, this is the only song in the List");
}
else if (document.all){
if (event.keyCode==99||event.keyCode==67)
window.close();
else if (event.keyCode==112||event.keyCode==80)
self.print();
else if (event.keyCode==110||event.keyCode==78)
alert("Sorry, this is the only song in the List");
}
}
//-->
</script>
</head>
<body>
<script language=\'javascript\'>
<!--
if (document.layers)
document.captureEvents(Event.KEYPRESS);
document.onkeypress=issueCommand
-->
</script>
<font size=6><u>P</u>ress P</font><p>
<font size=6><u>N</u>ext One</font><p>
<font size=6><u>C</u>lose Window</font><p>
</body>
</html>
是不是很简单.
- 上一篇: 不用询问关闭一个独立的窗口代码
- 下一篇: A~Z、0~9以及功能键的各键值编号
-= 资 源 教 程 =-
文 章 搜 索