Stop BGSOUND element in IE?

I added background music to the site that I create (don't kill me).
If in IE the element is called BGSOUND, I tried to pause music to pause, the button deletes the whole element and re-adds it, however
it turns out that deleting an item only restarts music for IE.

How to stop music played by a BGSOUND element through javascript?

Current Code:

<!--[if IE]> <BGSOUND id="bgmusic" SRC="<?php echo bloginfo('stylesheet_directory'); ?>/bgmusic.mp3" LOOP="true"> <![endif]--> 

When I run the document.getElementById('bgmusic').stop() command
I get an Object does not support the property or method 'stop'

+1
javascript html
source share
6 answers

I suggest using Flash instead. Not only will you have more control over the music, but it will work in browsers too. Today there are more Flash player users than IE .

0
source share

The ugly job is to set volume to -10000:

 document.getElementById('bgmusic').volume = -10000; 
+2
source share

I had a similar situation with the client page. I found that removing the src property of bgsound elements is the best way to avoid reloading the music issue in IE.

 var bgsoundElems = document.getElementsByTagName('bgsound'); for(var i = 0; i < bgsoundElems.length; i++){ bgsoundElems[i].src = ''; } 
+2
source share

When the user clicks Pause : deletes the item and stores it in a variable
When user clicks Play : Gets an element from a variable and adds it to the DOM

0
source share

I recommend using SoundManager .

It will use HTML5 sound whenever possible, and will otherwise return to Flash. And it has a unified and simple API .

0
source share

If you want to execute stop (), you can simply set src to an empty value. Works in IE11 (with emulation of IE8).

0
source share

All Articles