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

239
Visualizações
can i use playaudio() before refreshing my site?

hello, i have a simple button

<a onclick="window.location.href=window.location.href" class="btn"> Stop </a>

and i have an audio source

<audio id="myAudio"> <source src="https://myweb.com/files/tuntun.mp3" type="audio/mpeg"> </audio>

and this is javascript

<script> 
var x = document.getElementById("myAudio");
function playAudio() { 
x.play();
} 
</script>

i want the audio play before refreshing the page when i click the button, i tried but my audio stops while refresh. Bye the way i need it for ANDIOID Browser

I hope you can understand what I need because I'm bad at English

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You will have to run a function on click... That will play the audio and then will refresh the page.

<a onclick="playAudio()" class="btn"> Stop </a>

<audio id="myAudio"> <source src="https://myweb.com/files/tuntun.mp3" type="audio/mpeg"> </audio>

<script>
let stopFlag = false
let x = document.getElementById("myAudio");

function playAudio() {
  // Set a flag to know if the "stop" link was clicked
  stopFlag = true
  x.play();
}

// An event listener to reload the page after the video has ended if the "Stop" link was cliked
x.addEventListener('ended', () => {
  if(stopFlag){ 
    window.location.reload()
  }
})
</script>
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