title: window.onbeforeunload and window.onunload is not working in Firefox, Safari, Opera?
body: <p>In my chat application I need to get confirmation from user, when my application closes.</p>
  <p>So I used the <code>window.onbeforeunload</code> for confirmation alert and <code>window.onunload</code> for
  <code>logout()</code>.</p>
  <ol>
  <li><p>But both functions are working in IE and Chrome. (Application works fine)</p>
  </li>
  <li><p><code>window.onbeforeunload</code>  not working in Opera and my message will not get displayed in Firefox.</p>
  </li>
  <li><p><code>window.onunload</code> not working in Safari, Opera and Firefox.</p>
  </li>
  </ol>
  <p>My JavaScript code will be:</p>
  <pre class="lang-js prettyprint-override"><code>// Used for confirmation, to closing the window 
  window.onbeforeunload = function () {
  
      return  &quot;Are you sure want to LOGOUT the session ?&quot;;
  }; 
  
  // Used to logout the session, when browser window was closed 
  window.onunload = function () {
  
      if((sessionId != null)&amp;&amp;(sessionId!=&quot;null&quot;)&amp;&amp; (sessionId != &quot;&quot;))
          logout();
  };
  </code></pre>
  <p>I also tried the same function with JQuery,</p>
  <pre class="lang-js prettyprint-override"><code>&lt;script type=&quot;text/javascript&quot;&gt;
  
      $(window).on('beforeunload', function() {
          return 'Are you sure want to LOGOUT the session ?';
      });
  
      $(window).unload(function() {
          if ((sessionId != null) &amp;&amp; (sessionId != &quot;null&quot;) &amp;&amp; (sessionId != &quot;&quot;)) {
              logout();
          }
      });
      
  &lt;/script&gt;
  </code></pre>