浏览器选项卡上的Ajax调用问题关闭

时间:2015-03-12 11:03:01

标签: javascript jquery ajax

我在浏览器标签关闭时使用以下代码进行注销,

    var validNavigation = false;
        var refreshKeyPressed = false;
        function wireUpEvents() {

          var dont_confirm_leave = 0;
          var leave_message = 'You sure you want to leave?'
          function leavePage(e) {
            if (!validNavigation) {
              if (dont_confirm_leave!==1) {
                if(!e) e = window.event;
                //e.cancelBubble is supported by IE - this will kill the bubbling process.
                e.cancelBubble = true;
                e.returnValue = leave_message;
                //e.stopPropagation works in Firefox.
                if (e.stopPropagation) {
                  e.stopPropagation();
                  e.preventDefault();
                }
          if (!refreshKeyPressed) {
            $.ajax({
                 type: 'GET',
                 async: false,
                 url: "<?php  echo  Controller::createUrl('site/logout'); ?>",  
                 success: function ()
                   {

                    }
                });
                }

               // return leave_message;
              }
            }
          }
          window.onbeforeunload=leavePage;

          $("a").bind("click", function() {
            validNavigation = true;
          });

          $("form").bind("submit", function() {
            validNavigation = true;
          });

            $(document).bind('keydown',
      function(evt) {
          if (evt.which == f5key ) {
              refreshKeyPressed = true;
          }
      }
  );
        }
    $(document).ready(function(){   
        wireUpEvents();
    });

当我单击浏览器选项卡关闭时,它会询问&#34;离开此页面&#34;或者&#34;留在这个页面&#34;点击&#34;保留在此页面上的选项&#34;选项,然后我的Ajax代码执行,如何防止这个?

0 个答案:

没有答案