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

170
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
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