Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
In my javascript code, Firefox does not recognize double short key to browse a file

I want Alt+O short keys to browse a file in my web page. "Keydown" event can handle this issue perfectly in chrome however in Firefox nothing happens unless I do a click in page. Is there any solution to my problem?

$(document).ready(function(){
 $("body").keydown(function(e){

  var keyCode = (e.which) ? e.which : window.e.keyCode;

  if(e.altKey)
    if(keyCode == 79){ //Alt+O = openFile
      e.preventDefault();
      $("#xmlFile:hidden").trigger('click')
    }
   
 });
});

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<input type="file" id="xmlFile" style="display: none;" >
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can not use the trigger in this way this the answer helps you to understand. jQuery trigger doesn't work on Firefox

try this:

$(document).ready(function(){
 $("body").keydown(function(e){

  var keyCode = (e.which) ? e.which : window.e.keyCode;

  if(e.altKey)
    if(keyCode == 79){ //Alt+O = openFile
      e.preventDefault();
      document.getElementById('file-input').click();
    }
   
 });
});
<input id="file-input" type="file" name="name" style="display: none;" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!