How to call method on keypress :
we can use
document.onkeypress = KeyCheck; or
document.onKeydown = KeyCheck;
// to perform operation on esc key press
function KeyCheck(e) {
var KeyID = (window.event) ? event.keyCode : e.keyCode;
if (KeyID == '27') // 27 is the key code for ESC key
{
// To do
}
}
Note : onKeypress wont work for safari browser so we can use onkeydown
No comments:
Post a Comment