Question

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

Was it helpful?

Solution

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);
        }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top