how to check users leave a page

后端 未结 3 1139
轻奢々
轻奢々 2020-12-06 15:38

I\'d like to know that a user leave from a Web page. I think there might be three scenarios: 1. move to another page in the same Web site, either open a new window or load a

相关标签:
3条回答
  • 2020-12-06 16:20

    I just want to comment that there is probably no reliable, cross-browser solution for this... I know this doesn't add much value to your question, but if you can resolve your problem in any other way, I think it would be also more ergonomic.

    0 讨论(0)
  • 2020-12-06 16:28

    Take a look Mastering The Back Button With Javascript (it's the same principle). There are two relevant events: unload and beforeunload. Also see Best way to detect when user leaves a web page.

    0 讨论(0)
  • 2020-12-06 16:28

    You can't detect opening a new window or tab, but you can listen for the 'onunload' event.

    jQuery(window).bind("unload", function() {
        //your code here
    }); 
    

    This should fire when clicking on a link, closing the tab/window or pressing the back button.

    0 讨论(0)
提交回复
热议问题