title: Beforeunload is not working to redirect user to another page, how can I redirect user to another page/url when he attempts to close a window/tab?
body: <p>My following code isn't working to redirect the user to another page:</p>
  
  <pre><code>$(window).on('beforeunload',function(){
                          window.location.href="http://www.google.com;
                      }) ;
  </code></pre>
  
  <p>I want the user to be redirected to another page when he attempts to close the tab.
  What's the alternative and appropriate way to achieve this?</p>