Javascript/Jquery - Detect keypress except when file select dialog is showing -


i have modal box overlay user edits information in. 1 of ways close overlay pressing esc. have no problem working. however, within modal box section uploading file. while user selecting file, if user presses esc, closes 'select file' dialog box, keypress detected 'modal box close' script. have confirmation dialog ask user if they're sure want close box, still don't want action triggered if they're trying close 'file select' dialog.

what best approach here? there way determine whether browser's focus on 'file select' dialog versus part of actual page?

update: first 3 answers same, , solution simple i'm embarrassed asked. help. i'd accept answer since 3 same i'm not sure how choose favorite. guess i'll pick one. doesn't make other 2 less acceptable, though. all.

what best approach here? there way determine whether browser's focus on 'file select' dialog versus part of actual page?

why make complicated, have ability identify if user has clicked 'select file' button, can setup flag variable , set true whenever click button.

then keydown/keyup event can check flag , handle scenario accordingly.

edit:

example code:

var selectfilecode = {    isselectingfile: false,     click: function() {       this.isselectingfile = true;       //do stuff here open dialog    },    keydown: function(event) {      if (this.isselectingfile && event.which == 27) //pressed esc         //don't close modal, close select dialog    } };  $(function() {     $('.selectbtn').click(selectfilecode.click);     $('.modal').keydown(selectfilecode.keydown); }); 

you'll need make sure reset isselectingfile appropriately general approach.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -