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

163
Views
Javascript Keydown Not Triggering

I need help with getting the keydown of up arrow to trigger. I dont really understand what the problem with this is, most likely my messy formatting, but the keydown just doesn't trigger.

<script>
  window.addEventListener('keyup', (event) => {
    if (event.key == 'ArrowUp') {
        close();
    window.open("https://bsd.instructure.com/?login_success=1");
    }
});
</script>

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Check out the window.close() and window.open() API.

JavaScript cannot open windows if the browser blocks them. I tried your code and it says:
"Firefox prevented this site from opening a pop-up window. [Options]".

You can only open windows user-generated (e.g. button / link click).
Your event is working fine, but the browser is preventing the pop-up window.

window.addEventListener('keyup', (event) => {
  if (event.key == 'ArrowUp') {
    window.close(); // Blocked for certain standards
    window.open("https://bsd.instructure.com/?login_success=1"); // Blocked in the user's preferences
  }
});

I also recommend you use document events instead of window:

document.addEventListener('keyup', (event) => {
  if (event.key == 'ArrowUp') {
    // Action here
  }
});

You can use the window location property to navigate to pages.

document.addEventListener('keyup', (event) => {
  if (event.key == 'ArrowUp') {
    window.close();
    window.location.replace("https://bsd.instructure.com/?login_success=1");
  }
});

about 4 years ago · Juan Pablo Isaza Report

0

Only for the sake of completeness. as @Mike 'Pomax' Kamermans already answered the question correctly. bind the document object to the event instead of the window object.

document.addEventListener('keyup', (event) => {     
    if (event.key == 'ArrowUp') {
        console.log('Arrow UP');
        close();
    }
});

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!