How can I repeatedly play a sound while a javascript alert message is up and stop it when the alert message is dismissed?
I already have an HTML5 sound element on the page.
I’ve tried:
while(alert("foobar alert!"))
{ document.getElementById('foobarTune').play();};
to no avail.
I know I can just do:
document.getElementById('foobarTune').play();
alert("foobar alert!")
to get it to run before the alert once.
My main concern is to get it to run during the alert and then have it repeat while the alert box is up. And stop when alert box is dismissed by the user.
I assume you’re using html 5 to play the audio. See the loop attribute.
Then just call stop() on the line after the alert(). alert() blocks script execution, so it will work.