使用哪个事件处理程序记录离开页面-onunload或onbeforeunload? [英] Which event handler to use to record leaving page - onunload or onbeforeunload?

查看:110
本文介绍了使用哪个事件处理程序记录离开页面-onunload或onbeforeunload?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前有关使用javascript测量页面转换时间的问题没有任何答案,我将开始编写自己的代码(!).

Having not any answers to my previous questions about using javascript to measure page turn times, I'm going to start writing my own code (!).

为了测量花费的打结时间,我建议删除一个cookie,该cookie包含当用户离开页面浏览时的时间戳,然后在下一页中,将该时间与"now"进行比较,然后向一个将记录间隔的URL.

To measure the length of tie it takes, I'm proposing dropping a cookie containing a timestamp when the user browses away from a page, then in a subsequent page, comparing that time with 'now' and sending back a request to a URL which will log the interval.

似乎我可以将第一个代码块与2个可能的处理程序相关联-onunload()处理程序或onbeforeunload()?

It seems that there are 2 possible handlers I could associate the first block of code with - the onunload() handler or the onbeforeunload()?

重要的是,它可以在不支持处理程序的浏览器上无提示地失败,而不是在所有可能的浏览器中都可以移植.

It's more important that it fail silently on browsers with no/broken support for the handler, than it be portable across every possible browser.

有指针吗?有问题吗?

TIA

C.

推荐答案

onbeforeunload,它的真正目的是使用户有机会中止卸载,因此您应该进行onunload.

onbeforeunload is not supported by Opera, and is really meant to be used to give the user a chance to abort the unload, so you should go for onunload.

这篇关于使用哪个事件处理程序记录离开页面-onunload或onbeforeunload?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆