douwei4370
douwei4370
2016-07-26 07:05

如何在刷新页面时调用注销页面?

已采纳
/* The below code is used to make alert before reload a page */ 
 window.onbeforeunload = function() {
        return "";
}
/* The above code is used to make alert before reload a page */ 

/* i) The above code added to confirm user whether they need to refresh or not. (finished ) ii) If yes i want to call logout page (not yet finished - need help) */

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

4条回答

  • dongtuan1980 dongtuan1980 5年前

    Please try following code.

    <script type="text/javascript">
       window.onload = function() {
    
        if (confirm('Are you sure ?')) {
           // Call log out URL instead of Google
           window.location = "http://www.google.com";
        } else {
           // Do nothing!
           return false;
        }
    
    };
    </script>
    

    If user has select ok then He will be redirected to the Google.

    Please let me know if your require further information.

    点赞 评论 复制链接分享
  • duandou9931 duandou9931 5年前

    Use event.currentTarget.performance.navigation.type to determine the type of navigation.

    function CallbackFunction(event) {
        if(window.event) {
            if(window.event.clientX > 40 && window.event.clientY > 0) { 
                alert("refresh button is clicked");    
            }
    
        } else {
            if(event.currentTarget.performance.navigation.type == 1) {
                alert("refresh button is clicked");
            }             
        }
    }
    
    点赞 评论 复制链接分享
  • douchuang4402 douchuang4402 5年前

    You have to follow below snap code, I hope it will be helpful to you.

     window.onbeforeunload = function() {
       $.ajax({
           url: "your_logout_url", // which destroy user session
           type: 'GET',
           aync: false, // it is very usefull on serveside for waiting server response
           success: function(data){
               document.location.href='your_login_page_link'
           }
       });
    }
    
    点赞 评论 复制链接分享
  • dttvb115151 dttvb115151 5年前

    Call location.href = 'yourlogoutpage'. Based on your condition it will trigger the location .

    点赞 评论 复制链接分享