检测用户何时离开页面 [英] Detect when user navigates away from page
本文介绍了检测用户何时离开页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何检测用户是否正在离开我的网页?
有点像stackoverflow,如果你已经开始写帖子了。
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.
我试过 $(窗口).unload()
在jQuery中,但是我无法让它工作。
I have tried $(window).unload()
in jQuery, but I can't get it to work.
这句话并不完全正确,在IE9中它起作用,实际上是有点太好了。如果刷新页面,它也会弹出。
但在Chrome中,没有任何触发器。
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.
推荐答案
试试这个
$(window).bind('beforeunload', function(){
return 'DataTest';
});
这篇关于检测用户何时离开页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文