Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8382325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:54:22+00:00 2026-06-09T16:54:22+00:00

I’m creating pages for a small web-based game which must have some background music

  • 0

I’m creating pages for a small web-based game which must have some background music playing. Those pages should be compatible with most desktop browsers, including IE8 (but we can ignore the mobile browsers).

Of course I’d like to allow the user to stop the music. And this is where it gets tricky.

Here’s what I use currently (with jQuery) :

<audio id="main_audio" autoplay="autoplay" preload="auto" loop="loop">
    <source src="sounds/bgmusic.mp3" type="audio/mpeg" />
    <source src="sounds/bgmusic.ogg" type="audio/ogg" />
    <embed hidden="true" autostart="true" loop="true" src="sounds/bgmusic.mp3" />
</audio>
<div id="controls" class="controls">
    <a id="playpause" class="play">Play/Pause</a>
</div>
<script>
    function isPlaying(audio) {return !audio.paused;}
    var a = document.getElementById('main_audio');
    $('#playpause').on('click', function() {
        if (isPlaying(a)) {
            a.pause();
        } else {
            a.play();
        }
    });
</script>

This works fine in all browsers, but IE. (I’m on Windows XP so testing on IE8 currently.)
On IE8, the audio starts playing (which is good) but the controls don’t do anything so it’s impossible to stop the music (and restart it).

How can I make this script work for IE too? In other word, interact with the embed tag (but only in IE)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T16:54:24+00:00Added an answer on June 9, 2026 at 4:54 pm

    Try next code:

    <audio id="main_audio" autoplay="autoplay" preload="auto" loop="loop">
        <source src="sounds/bgmusic.mp3" type="audio/mpeg" />
        <source src="sounds/bgmusic.ogg" type="audio/ogg" />
        <embed id="main_audio_ie8" hidden="true" autostart="true" loop="true" src="sounds/bgmusic.mp3" />
    </audio>
    <div id="controls" class="controls">
        <a id="playpause" class="play">Play/Pause</a>
    </div>
    <script>
        var isPlaying = function(audio) {return !audio.paused;}
        var a = document.getElementById('main_audio');
        if(!(a.play instanceof Function)){
            a = document.getElementById('main_audio_ie8');
            isPlaying = function(audio) {return audio.playState==2;}
        }
        $('#playpause').on('click', function() {
            if (isPlaying(a)) {
                a.pause();
            } else {
                a.play();
            }
        });
    </script>
    

    Another variant (code must work if WMPlayer.OCX exist on system; checked on Win2K+IE6SP1+WMP7, WinXP+IE6SP1+WMP9, WinXP+IE8+WMP11):

    <audio id="main_audio" autoplay="autoplay" preload="auto" loop="loop" volume="1.0">
        <source src="sounds/bgmusic.mp3" type="audio/mpeg" />
        <source src="sounds/bgmusic.ogg" type="audio/ogg" />
        <object id="main_audio_ie8" classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6" style="display:none;"> 
            <param name="URL" value="sounds/bgmusic.mp3" />
            <param name="uiMode" value="invisible" /> 
            <param name="autoStart" value="true" />
            <param name="volume" value="100" />
            <param name="playCount" value="2147483647" /> <!-- (Int32) 2^31-1==2147483647 - maximum allowed count (for 1 second length audio is equals to 68+ years) -->
        </object> 
    </audio>
    <div id="controls" class="controls">
        <a id="playpause" class="play">Play/Pause</a>
    </div>
    <script type='text/javascript'>
    window.onload=function(){
        var isPlaying,a=document.getElementById('main_audio');
        if(a.play instanceof Function)isPlaying=function(audio){return !audio.paused;};
        else{
            a=document.getElementById('main_audio_ie8');
            isPlaying=function(audio){return audio.playState==3;};
            a.play=function(){this.controls.play();}
            a.pause=function(){this.controls.pause();}
        }
        document.getElementById('playpause').onclick=function() {
            if (isPlaying(a)) {
                a.pause();
            } else {
                a.play();
            }
        };
    };
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I used javascript for loading a picture on my website depending on which small
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a text area in my form which accepts all possible characters from
I have some data like this: 1 2 3 4 5 9 2 6
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.