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

249
Views
JavaScript: how to stop an audio on autoplay by keyboard

I want to know how to stop an audio that is set to "autoplay" using the X key on the keyboard. I have tried in a couple of method but it doesn't work. That's my code:

JavaScript:

var source = "audio/homepage_benvenuto.mp3";
        var audio = document.createElement("audio");
        audio.autoplay = true;
        audio.load()
        audio.addEventListener("load", function() 
        { 
                audio.play();
        }, true);
        audio.src = source;

window.addEventListener("keydown", checkKeyPressed, false);
        function checkKeyPressed(e) 
        {
if (e.keyCode == "88") // 88 = X: interrompe audio in corso
            {
                player.pause();
                player.currentTime = 0;
                document.getElementById('audioA').pause();
            }
}

about 4 years ago · Juan Pablo Isaza
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!