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

  • SEARCH
  • Home
  • 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 9156923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:53:14+00:00 2026-06-17T12:53:14+00:00

Okay, so I’ve got something as simple as this: <audio autoplay=’autoplay’ loop=’loop’ id=’audio’ controls>

  • 0

Okay, so I’ve got something as simple as this:

<audio autoplay='autoplay' loop='loop' id='audio' controls>
  <source src='http://www.w3schools.com/html/horse.ogg'/>
  <source src='http://www.w3schools.com/html/horse.mp3'/>
</audio>

Now, when I play the audio on an iOS device, it loops fine and everything, however, when I close the browser window, or switch tabs, it just keeps on looping and the only way to pause it is if I shut the browser tab. I tried removing the loop='loop' and replaying it onended with JavaScript, and that works, but with audio that is about 1.5 mins long, it can still be pretty annoying. but that didn’t work either because the ended event fires even when the browser isn’t open.

Demo in which the sound is the first one I could find online, but note that my actual sound is pretty long, so I do need to pause it when the browser window is closed.

I’ve tried pausing it onblur, onunload and onbeforeunload to no avail. Is there a way to stop the audio from playing in the background?

  • 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-17T12:53:15+00:00Added an answer on June 17, 2026 at 12:53 pm

    Managed to find a solution:

    Make use of a loop, to check if the user is on the webpage. Store the time.

    var lastSeen;
    var loop = function (){
        lastSeen = Date.now();
        setTimeout(loop, 50);
    };
    loop();
    
    var music = document.getElementById('music');
    music.addEventListener('timeupdate', function (){
        if(Date.now() - lastSeen > 100){
            this.pause();
        }
    }, false);
    

    That’s roughly what my file looks like. Since the timeupdate event fires on an audio element continually if it’s playing, I only have to check when my loop was last called. If it was called more than 100ms ago, I pause the music. Worked like a charm on the iPad I tested on.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay this question is very simple: I have a facebook page, and a website.
Okay, I have GOT to be missing something totally rudimentary here. I have an
Okay, I really know this has GOT to be the long way around doing
Okay, this should be really simple, but I have searched all over for the
Okay, this is the case: I got a generic base-class which I need to
Okay, this might be a very silly beginner question, but: I've got an ClassA,
Okay the answer to this may be really simple but I have been searching
Okay, I got this small program which tags (as in ID3v2.4 etc.) some music
Okay, I feel a bit foolish for having to ask this but I guess
Okay, this is probably a very basic question; but, I'm just getting back in

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.