junior developper
junior developper

Reputation: 448

Play sound and show alert at the same time javascript

Here is my javascript code where i'm trying to play sound then show alert but i always get the alert first and when i click ok the sound is played.

 <script>
            function play() {
                var audio = document.getElementById("audio");
                audio.play();
                alert('Extraction is finished');
            }
  </script>

I'm calling this function in oncomplete command button. I need to play the sound first then show the alert or both at the same time. How can i make this work???

Upvotes: 1

Views: 3392

Answers (1)

seba47
seba47

Reputation: 320

You could set a timeout (change the milisecondsif you want: 1000 )

function play() {
            var audio = document.getElementById("audio");
            audio.play();
            setTimeout(function(){alert("Extraction is finished");},1000);
        }

Upvotes: 5

Related Questions