Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

238
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!