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

244
Vistas
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 Respuestas
Responde la pregunta

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 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