2015-06-23 49 views
0

在为Chrome停止前不会发生指定的URL指定在Internet Explorer和Chrome中调用正文之前放置的以下脚本(以及任何其他浏览器)。但重定向到指定的URL只发生在IE中。而不是document.location.href,我也试过window.locationwindow.location.href,没有完整的网址(如下面的脚本)和完整的网址(http://localhost:8080/MyApp/LogoutController)以及。它在所有情况下都会使用URL,但只能使用IE。使用document.location.href或window.location或window.location.href

<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> 

回答

1

这是一个安全嗅觉。

尝试通过Ajax加载“LogoutController”,如果你只是想通知。

+0

谢谢@亨利。它开始通过铬中的ajax重定向到网址。但是当我在部署之后立即按下F5时,ajax调用并不是第一次。之后,它工作正常。这是我正在使用的:$(document).ready(function(){ \t \t $(window).bind('beforeunload',function(event){ //调用servlet,注销用户 \t \t $获得( “LogoutController?” + $。现在()函数(数据){ \t \t警报( “您已被注销”); \t \t}); \t \t/**警报对于IE **/ \t \t alert(“You have been logged out”); \t \t}); \t \t});' – user2918640

相关问题