1

I want to open file upload when page loaded.I used this code but it not working.

<input type="file"  id="browse" style="visibility:hidden;"  
accept="image/*" capture="camera" />    

<input style="background-color: #008CBA; color:white;"  type="button" 
value="Scan BarCode" id="fakeBrowse" />

   <script>
    window.onload=function(){
     $('#browse').trigger("click");
    }; 
    </script>

Please guide me how it will work.Thanks

user
  • 25
  • 7
  • http://jsfiddle.net/CSvjw/1/ try this. this is something close to what you want to achieve – Akshay Mulgavkar May 06 '19 at 04:21
  • As I understand you want to open the file upload dialog on page load. It may still be disabled for most browsers as seen in [this](https://stackoverflow.com/questions/210643/in-javascript-can-i-make-a-click-event-fire-programmatically-for-a-file-input) and [this](https://stackoverflow.com/questions/25886480/trigger-click-on-input-file) question. There are some tips on what you can do though. – Cray May 06 '19 at 04:36
  • @Cray i changed my code ,but its working on IE not supporting on chrome,i want to do it on chrome is it possible – user May 06 '19 at 04:57
  • I never tried it, but based on the answers in previous questions it probably is not. – Cray May 06 '19 at 06:14

1 Answers1

0

Try this

<html>
  <body>
    <input type="file" style="display: none" />
    <button>Open File Dialog</button>
    <script src="https://code.jquery.com/jquery-2.2.4.js"></script>
    <script>
      $("button").on("click", function() {
        $("input").trigger("click");
      });
    </script>
  </body>
</html>
  • 1
    These answers are working on clcik event i want to open file input dialog when page load – user May 06 '19 at 04:34