title: How do I stop a page from unloading with standardized JavaScript (Not `onbeforeunload`)
body: <p><em>Before you relink me, I've read questions like <a href="https://stackoverflow.com/questions/1299452/how-do-i-stop-a-page-from-unloading-navigating-away-in-js">How do I stop a page from unloading (navigating away) in JS?</a>, but they deal with HTML4 and below. I want an answer that utilizes the HTML5 event attribute <code>onunload</code>. I also want this to be as pure as possible, that is without external libraries or plugins like jQuery or Flash and only using standardized code (<strong>PURE</strong> HTML, CSS, and JavaScript, nothing platform-dependant).</em></p>
  
  <p><strong>Before you tell me to use <code>onbeforeunload</code>, note that it is <em>NON-STANDARD</em>, and therefore does not fit my criteria as described above. It does NOT work on all browsers, especially those made before IE implemented it.</strong></p>
  
  <h2>Question</h2>
  
  <hr>
  
  <p>On my site, I have several music players, and if any one of them is playing when the user attempts to navigate away from the page, I want to popup a dialog box ensuring that they intended this and that they understand that this will stop the audio stream, and if they choose "yes" or "OK", it proceeds with the navigation, but if they click "no" or "Cancel", it stays on the same page and keeps playing the audio without a break. <strong>How do I use JavaScript to cancel the page unloading WITHOUT USING <code>ONBEFOREUNLOAD</code>?</strong></p>
  
  <h2>Code so far</h2>
  
  <hr>
  
  <p>I have the following code so far, but no idea how to stop unloading:</p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;&lt;html&gt;
  &lt;head&gt;
      &lt;script&gt;&lt;!-- Loading Scripts --&gt;
      function unloadTasks(){
          window.alert(":" + playing + ":");
          if (playing &amp;&amp; !window.confirm("A podcast is playing, and navigating away from this page will stop that. Are you sure you want to go?"))
              window.alert("Here is where I will stop the page from unloading... somehow");
      }
      &lt;/script&gt;
      &lt;script&gt;&lt;!-- Player Scripts --&gt;
      var playing = false;
      function logPlay(){
          playing = isPlaying("e1audPlayer");
      }
      function isPlaying(player){
          return document.getElementById(player).currentTime &gt; 0 &amp;&amp; !document.getElementById(player).paused &amp;&amp; !document.getElementById(player).ended;
      }
      &lt;/script&gt;
  &lt;/head&gt;
  &lt;body onunload="unloadTasks()"&gt;
  &lt;audio id="e1audPlayer" style="width:100%;" controls="controls" preload="auto" onplaying="logPlay()" onpause="logPlay()"&gt;
      &lt;source src="http://s.supuhstar.operaunite.com/s/content/pod/ADHD Episode 001.mp3" type="audio/mpeg"/&gt;
      &lt;source src="http://s.supuhstar.operaunite.com/s/content/pod/ADHD Episode 001.ogg" type="audio/ogg"/&gt;
      Your browser does not support embedded audio players. Try &lt;a href="http://opera.com/"&gt;Opera&lt;/a&gt; or &lt;a href="http://chrome.com/"&gt;Chrome&lt;/a&gt;
  &lt;/audio&gt;
  &lt;a href="http://example.com/"&gt;Link away&lt;/a&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><a href="http://s.supuhstar.operaunite.com/s/content/pod/playerTest.htm" rel="nofollow noreferrer">Working example</a></p>