Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

163
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda