0

The following script placed just before the end of the body gets called both in Internet Explorer and Chrome (and any other browser). But redirection to specified URL happens only in IE. Instead of document.location.href, I also tried window.location and window.location.href , without full url (like in the script below) and with full url (http://localhost:8080/MyApp/LogoutController) as well. It goes to URL in all the cases, but only with IE.

<script type="text/javascript">
            // this method will be invoked when user leaves the page, via F5/refresh, Back button, Window Close
            $(window).bind('beforeunload', function(event){
            // invoke servlet, to logout the user
            document.location.href = 'LogoutController';
            alert("You are logged out"); 
            });
        </script>
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
user2918640
  • 473
  • 1
  • 7
  • 25

1 Answers1

1

It's a security mesure.

Try to load the "LogoutController" by Ajax if you just want to be notified.

Thibault Henry
  • 816
  • 6
  • 16
  • Thanks @Henry. It started redirecting to url through ajax in chrome. But the ajax call is not working the first time when I press F5 right after the deployment. Afterwards, it works fine. This is what I am using: `$( document ).ready(function() { $(window).bind('beforeunload', function(event){ // invoke the servlet, to logout the user $.get("LogoutController?" + $.now() , function(data) { alert("You have been logged out"); }); /** Alert for IE **/ alert("You have been logged out"); }); });` – user2918640 Jun 24 '15 at 08:42