title: What is a foolproof alternative to $(window).unload()?
body: <p>I was reading jQuery documentation for the function <code>.unload()</code> given in the <a href="https://api.jquery.com/unload/" rel="nofollow noreferrer">jQuery API Documentation</a></p>
  
  <p>It is written clearly that <code>.unload()</code> will is deprecated in versions after 1.8 and removed completely in 3.x.</p>
  
  <p>I have a local intranet application that is dependent upon this <code>.unload()</code> function.</p>
  
  <p>Do I have to manually rely on <code>window.onbeforeunload</code> function and see that a particular browser supports this or not, or can anyone help me in finding a more generic solution for the same.</p>
  
  <p>As suggested by Kevin, I tried</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$(window).on("unload", function(e){
      return confirm("Do you really want to exit");
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://code.jquery.com/jquery-3.2.1.min.js"&gt;&lt;/script&gt;
  Testing JQuery Unload in 3.x Version</code></pre>
  </div>
  </div>
  </p>
  
  <p><a href="https://jsfiddle.net/vibs2006/bqge8x22/" rel="nofollow noreferrer">Fiddle</a></p>
  
  <p>But it is not working</p>