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>
It's a security mesure.
Try to load the "LogoutController" by Ajax if you just want to be notified.