cleeclee Posted November 14, 2012 Share Posted November 14, 2012 Hi i've managed to include a simple pop-up in my website and would like to add a sound to play when the pop up appears and the sound to stop when the pop up closes. I've found articles which allows me to add music to the web page body itself only. Please help? ^^ below is a part of my code that is used to make the pop up appear <html> <span id="someelem">Please hold on!</span> </html> <script> (function(){ setTimeout(showTooltip, 20000) })(); function showTooltip() { alert("WARNING ENERGY LEVEL CRICTICALLY HIGH"); } </script> <style> #someelem { cursor: pointer; } </style> Quote Link to comment Share on other sites More sharing options...
codefossa Posted November 14, 2012 Share Posted November 14, 2012 Add the sound (possibly looping). Show the alert. This will basically pause your script until it's dealt with. Remove sound after the alert. There's quite a few ways to add a sound. http://www.w3schools.com/html/html_sounds.asp Quote Link to comment Share on other sites More sharing options...
cleeclee Posted November 14, 2012 Author Share Posted November 14, 2012 Hi thank you for the reply. I've added the codes all into my simple script and none seems to have worked for me. Quote Link to comment Share on other sites More sharing options...
codefossa Posted November 14, 2012 Share Posted November 14, 2012 Create the element (your audio player) into a variable. Append it to the body for it to play, then remove it afterwards. What are you having problems with? Quote Link to comment Share on other sites More sharing options...
cleeclee Posted November 15, 2012 Author Share Posted November 15, 2012 I am able to play the sound already. Thank you for your help! Could i just also ask another question too? I am able to play only 1 music. After that the other one doesn't play. Here's what i did, it's a very newbie work cause i only have about 6 weeks of experience. Hope you can guide me along. Thank you very much! <html> <audio controls="controls" autoplay="autoplay"> height="0.5" width="0.5"> <source src="silence.mp3" type="audio/mp3"> <source src="silence.ogg" type="audio/ogg"> <embed height="100" width="100" src="silence.mp3"> <source src="alarm.mp3" type="audio/mp3"> <source src="alarm.ogg" type="audio/ogg"> <embed height="100" width="100" src="alarm.mp3"> </audio> </html> Quote Link to comment Share on other sites More sharing options...
cleeclee Posted November 15, 2012 Author Share Posted November 15, 2012 Hi sorry Xao, i realized that by having 2 audio tags will solve the problem. But the sounds are playing together. how do i play the first one then the second one? I've tried using the javascript setTime function. But it doesnt work. I placed the script between the two audio tags. Is there another way round it? Quote Link to comment Share on other sites More sharing options...
codefossa Posted November 15, 2012 Share Posted November 15, 2012 I'm pretty sure audio tags allow .play() function. Set autoplay off and no loop, you should be able to play them whenever ya want. // In case you may have done it wrong? Or thought it was actually setTime instead of setTimeout setTimeout(func, milli); Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.