处理浏览器关闭并使会话无效

时间:2013-07-02 11:51:41

标签: javascript jquery

我使用下面的代码检测浏览器关闭事件,然后使会话无效。如果直接点击浏览器关闭按钮,它工作正常。如果我点击一些< a href>在页面中,window.onbeforeunload被触发,会话失效。

请让我知道如果某个机构知道解决此问题的方法。

/*JS code begins here*/

/*Global js variable to decide whether to call session invalidate function*/

    var validNavigation = false;
        //Called when page loads initially
        jQuery(document).ready(function() {
           //Call to wireupEvents
        wireUpEvents();

                });
        //Function called when the page loads
            function wireUpEvents() {


            window.onbeforeunload= function() {





                if (!validNavigation) {
                           /*This JS function calls my managed bean method to invalidate session.*/
                    windowCloseJsFunction();
                }
            }


        // Attach the event keypress to exclude the F5 refresh
            jQuery(document).bind('keypress', function(e) {
                if (e.keyCode == 116) {

                    alert('116');
                    validNavigation = true;
                }
            });

            // Attach the event click for all links in the page
            jQuery("a").bind("click", function() {
                alert('click a');
                validNavigation = true;

            });

            // Attach the event submit for all forms in the page
            jQuery("form").bind("submit", function() {
                alert('form');
                validNavigation = true;
            });

            // Attach the event click for all inputs in the page
            jQuery("input[type=submit]").bind("click", function() {
                alert('input');
                validNavigation = true;
            });
        //Attach button click for all inputs in the page
            jQuery("input[type=button]").bind("click", function() {
          validNavigation = true;
        });

        }

    /*JS code ends here*/

0 个答案:

没有答案