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

173
Vistas
how can i give a button two seperate functions in html

so im trying to create a button that takes you to the second page of my website aswell as playing a sound file. the problem im having is that it goes to the second page without playing the sound. currently, my code looks like this:

<body>
    <audio id="sound1" src="sound.mp3" preload="auto"></audio>

    <button type="submit" onclick="document.getElementById('sound1').play(); 
    location.href='page2.html';">enter</button>
</body>

does anyone know why this is happening, and if so, how can i fix it.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

When navigating to a new page, the previous page's lifecycle ends, including media that's playing. Consider using a Single Page Application (SPA) pattern to change URLs and content while maintaining playing audio.

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