title: Stop HTML5 audio from looping when iOS Safari is closed
body: <p>Okay, so I've got something as simple as this:</p>
  
  <pre><code>&lt;audio autoplay='autoplay' loop='loop' id='audio' controls&gt;
    &lt;source src='http://www.w3schools.com/html/horse.ogg'/&gt;
    &lt;source src='http://www.w3schools.com/html/horse.mp3'/&gt;
  &lt;/audio&gt;
  </code></pre>
  
  <p>Now, when I play the audio on an iOS device, it loops fine and everything, <em>however</em>, 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 <code>loop='loop'</code> and replaying it <code>onended</code> with JavaScript, <strike><em>and that works, but with audio that is about 1.5 mins long, it can still be pretty annoying.</em></strike> but that didn't work either because the <code>ended</code> event fires even when the browser isn't open.</p>
  
  <p><a href="http://jsfiddle.net/x843X/" rel="nofollow">Demo</a> 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 <code>pause</code> it when the browser window is closed.</p>
  
  <p>I've tried pausing it <code>onblur</code>, <code>onunload</code> and <code>onbeforeunload</code> to no avail. Is there a way to stop the audio from playing in the background?</p>