0

Say, you want to play a beep.mp3 on the hour so you wrote JavaScript code that does this, which is not all that hard. But when the user switches to another tab, and your page soon becomes living in an inactive tab, you won't hear those audio alerts any more.

Is there a remedy for this?

Marco Scabbiolo
  • 7,203
  • 3
  • 38
  • 46

1 Answers1

0

If we include audio in HTML then we can play by using JavaScript, even if the browser tab is inactive.

<body>
    <audio id="beep" src="audio source file" preload="auto" ></audio>

    <script>
        function playBeep() {
           document.getElementById("beep").play();
        }
        playBeep();
    </script>
</body>
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
vvsanil
  • 65
  • 1
  • 10
  • 1
    Does `` belongs in ``? – Peter Mortensen Jun 12 '16 at 15:23
  • ` – Ami Hollander Jun 12 '16 at 15:52
  • @Peter Mortensen You can find good answer here [where-to-place-javascript-in-a-html-file](http://stackoverflow.com/questions/196702/where-to-place-javascript-in-a-html-file) – vvsanil Jun 13 '16 at 04:53