Jump to content

Recommended Posts

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>

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

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>

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?

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);

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.