Detecting if the file input dialog is open

前端 未结 4 1521
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-18 00:24

How can I go about detecting if the file input dialog is currently open?

I\'m trying to integrate some file upload functionality into a popup (bootstrap style) model

4条回答
  •  不思量自难忘°
    2020-12-18 01:09

    Based on Nikita's answer. If you check for focus on the input field before firing your code it solves the issue:

    $('input[type="file"]').on('keydown',function(e){
    
        //Prevents code from firing if file browser is open
        if($(this).is(':focus')){
    
            //run code here that should only be applied when the dialog box is closed
    
        }
    
    });
    

提交回复
热议问题