2

I tried to open file dialog by 'oncontextmenu' event, but it didn't work! I can do this by other event, but only 'oncontextmenu' didn't work.

<html>
  <head>
    <script type="text/javascript">
     function wrapper(ev)
     {
       ev.preventDefault();
       document.getElementById('file').click();
       return false;
     }
    </script>
  </head>
  <body>

  <input id="button" type="button" oncontextmenu="wrapper(event)">
  <input id="file" type="file">

  </body>
</html>

I want to know solution or why it doesn't work. Thanks for reading.

1 Answers1

0

It doesn't work because some browsers disallow triggering file input programatically. See this question for numerous attempts of this with questionable success.

Community
  • 1
  • 1