I am trying to make a shortcut with javascript. It works with FF, but not IE8. I am using this code -
document.onkeydown=function(e) { if(e.which == 83) { alert("hello"); } }
Please give me a simple code that will support all browsers. Thanks to
To make your own cross-browser you need:
document.onkeydown = function(e) { e = e || window.event; var keyCode = e.keyCode || e.which; if(keyCode == 83) { alert("hello"); } }
Check out the above snippet here .
Read this.
Are you allowed to use jQuery? Because this will work:
$(window).keydown(function(event){ if(event.keyCode == 83){ alert('hello'); } });
Partially strengthened from here