'IE9 - Not able to disable ESC key to stop closing lightbox
I have used below code - Its not working on IE9 but works fine on Firefox and Chrome
$(document).ready(function(){
if (document.addEventListener) { // all browsers except IE before version 9
document.addEventListener ("keydown", win_onkeydown_handler, false);
}
else {
if (document.attachEvent) { // IE before version 9
document.attachEvent ('onkeydown', win_onkeydown_handler);
}
}
function win_onkeydown_handler(e, keyEventArgs) {
if (e.keyCode == 27) {
return false;
}
}
}
Solution 1:[1]
You have to define event.returnValue
for older IEs, and prevent the default action in IE>8 :
function win_onkeydown_handler(e, keyEventArgs) {
if (e.keyCode == 27) {
e.returnValue = false;
if (e.preventDefault) {
e.preventDefault();
}
return false;
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Teemu |