input type=“file” auto click

后端 未结 3 557
鱼传尺愫
鱼传尺愫 2021-01-13 08:53

How do I automatically open the browse dialog of an input type=\"file\" when the page first opens?

相关标签:
3条回答
  • 2021-01-13 09:33

    I don't think you should do this. If you've ever visited a MySpace page, you know how frustrating it can be when a web page activates things on its own when the page loads.

    Don't violate how the UI is supposed to work, let the user ask for the dialog.

    Besides, if the users instinctively closes it like a popup, and then realizes they needed it, it may not be obvious how they should get the dialog back. Then they will reload the page just to show the dialog again -- all frustrating things you could be avoiding.

    That being said, I'm not sure why you want to do this in the first place. This is just my first reaction to what you're asking.

    0 讨论(0)
  • 2021-01-13 09:40

    fire the click event on the button on document ready

    $(document).ready(function() {
        $("#buttonid").click();
    });
    
    0 讨论(0)
  • 2021-01-13 09:44

    This is completely impossible in Firefox.

    In other browsers, you can:

    document.getElementById('inputId').click();
    
    0 讨论(0)
提交回复
热议问题