admin管理员组文章数量:1289845
How do I detect that a user is navigating away from my page? Kind of like stackoverflow does, if you have started writing a post.
I have tried $(window).unload()
in jQuery, but I can't get it to work.
This statement is not entirely true, in IE9 it works, in fact a bit too well. It also pops up, if the page is refreshed. But in Chrome, nothing triggers.
How do I detect that a user is navigating away from my page? Kind of like stackoverflow does, if you have started writing a post.
I have tried $(window).unload()
in jQuery, but I can't get it to work.
This statement is not entirely true, in IE9 it works, in fact a bit too well. It also pops up, if the page is refreshed. But in Chrome, nothing triggers.
Share Improve this question edited Nov 29, 2012 at 13:35 Nicolai asked Nov 29, 2012 at 13:22 NicolaiNicolai 2,9158 gold badges45 silver badges55 bronze badges 4- look at this: stackoverflow./questions/3032249/… – silly Commented Nov 29, 2012 at 13:24
- 1 Also here: kbeezie./cross-browser-exit-pop – beyond-code Commented Nov 29, 2012 at 13:25
- @Roysvork, that seems to work for me! Care you to submit an answer? – Nicolai Commented Nov 29, 2012 at 13:44
- 1 There is an excellent article on the matter here: kbeezie./cross-browser-exit-pop This explains all the ins and outs of the different browsers. Enjoy! – beyond-code Commented Nov 29, 2012 at 14:11
1 Answer
Reset to default 10Include the jQuery library in your code, and then try out this
$(window).bind('beforeunload', function(){
return 'DataTest';
});
JsFiddle Demo
本文标签: javascriptDetect when user navigates away from pageStack Overflow
版权声明:本文标题:javascript - Detect when user navigates away from page - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741423497a2377942.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论