Web Programming

JQUERY To Open Page on Specific Button Keypress

Simply add this below JQUERY function in your html/php page :

$(function() {
$(document).keypress(function(event) {
var ch = String.fromCharCode(event.keyCode || event.charCode);
switch (ch) {
case ‘a’: case ‘A’:
window.location.href = ‘http://www.danielzabath.com’;
break;
case ‘c’: case ‘C’:
window.location.href = ‘http://www.google.com’;
break;
}
});
});

The above code will open http://www.danielzabath.com page when you press ‘A’ button on your keyboard, and ‘C’ button will redirect you to http://www.google.com.

source: forum.jquery.com

Leave a Reply