开发者

jQuery beforeunload

开发者 https://www.devze.com 2023-02-24 05:39 出处:网络
I have been rewriting a classic asp Shopping basket using jQuery and Ajax. My problem is i want a logout functionality when the user closes the browser. this works but if i refresh the page the code t

I have been rewriting a classic asp Shopping basket using jQuery and Ajax. My problem is i want a logout functionality when the user closes the browser. this works but if i refresh the page the code to logout fires and i lose everything. 开发者_JS百科I found this jquery code piece:

    var inFormOrLink = false;
    $('a').live('click', function () { inFormOrLink = true; });
    $('form').bind('submit', function () { inFormOrLink = true; });
    $(window).bind("beforeunload", function () {
        if (inFormOrLink == false) {
            $.post("logout.asp");
        }

    })

Does anyone have any ideas how i can perform logout.asp ONLY when the user closes the browser OR indeed changes to a new website. But keep the information while in the Application (in IIS).


The beforeunload is fired when you leave/refresh the current page, and you can only successfully run code that blocks the browsing session, such as alert() or prompt().

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号