javascript - Firefox: stopping propagation of enter keypress on confirm popup? -
i'm having unusual problem occuring in firefox. have run of mill dialog:
var cnf = confirm(message); if(cnf) { blah blah } the problem have keyup handler on document somehow fires when user types come in confirm dialog.
$(document).bind('keyup', function(e) { console.log('someone nail ' + e.which); }); when user hits come in confirm, console logs "someone nail 13" doesn't happen in other browser (and afaik shouldn't happen)
is there way me prevent propagation of keydown event or somehow avoid behavior?
here's jsfiddle depicting problem: clicky
best solution think over-ride confirm method in firefox.
// ideally should utilize feature detection can't think of improve way if ( true ) { // check firefox $.browser.mozilla (function(window){ var _confirm = window.confirm; window.confirm = function(msg){ var keyupcanceler = function(ev){ ev.stoppropagation(); homecoming false; }; document.addeventlistener("keyup", keyupcanceler, true); var retval = _confirm(msg); settimeout(function(){ document.removeeventlistener("keyup", keyupcanceler, true); }, 150); // giving plenty time fire event homecoming retval; }; })(window); } above code disable keyup events reaching dom elements using capturing phase.
please check updated jsfiddle: http://jsfiddle.net/mtrpq/2/
javascript jquery firefox
No comments:
Post a Comment