Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

166
Visualizações
Audio file won't play when hovering over image - until a click event takes place on page

I want an audio file (mp3) to play when the user hovers over an image.

The included code won't play the mp3 on hover, until you click somewhere on the page. Then hovering over the image will work. I imagine this is something to do with how browsers handle audio files rather than the code?

This is for a bit of fun and an easter egg on a 404 page. So less bothered about accessibility here as it's ok in this context.

So my question is, is there a workaround for this or do I need to execute the script in a different way?

var test = document.getElementById("test");
test.addEventListener("mouseover", function( event ) {   
  var audio = document.getElementById("audio");
  audio.play();
}, false);
          
<img src="https://www.fillmurray.com/600/400" id="test" />
          
<audio id="audio" preload="auto" src="https://file-examples.com/storage/fe26085c7f62d2ca79a7a30/2017/11/file_example_MP3_700KB.mp3"></audio>
            
       

about 4 years ago · Santiago Gelvez
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda