Javascript热键兼容ie,firefox
<textarea onkeydown="keyHanlder(event)">
</textarea>
<script>
function keyHanlder(e){
if(e.ctrlKey&&e.keyCode==13){
alert('"Ctrl+Enter"');
if(e.preventDefault)e.preventDefault();
else e.returnValue=false;
}
}
</script>
非IE浏览器调用函数会自动返回参数event,通过它可以获取键盘
<SCRIPT LANGUAGE="JavaScript">
<!--
function hotkey(e)
{
//判断浏览器
var ex = navigator.appName;
var a = ex=='Microsoft Internet Explorer'? window.event.keyCode : e.which;
alert(a);
switch(a){
case 83:
window.open('Myhomepage/search.htm','show')
break;
case 70:
window.open('Myhomepage/favorite.htm','show')
break;
}
}// end hotkey
document.onkeydown = hotkey; //当onkeydown 事件发生时调用hotkey函数
//-->
</SCRIPT>