当 Firefox 鼠标事件不存在时,在 onbeforeunload 上获取它?
所以onbeforeunload事件没有鼠标信息,那么如何获取鼠标XY呢?我想知道用户是否单击浏览器上的关闭按钮立即注销(20 分钟的会话对于资源来说太长,但是,我们不会缩短它以使客户生气)。
在 IE 上,我可以简单地访问鼠标信息来确定用户在 onbeforeunload 期间是否单击了关闭按钮。对于 FF,我想使用参数化事件,遗憾的是它根本没有鼠标信息。
(注意,如果存在真正的 onBrowserClose 事件,则不需要这样做。由于情况并非如此,我正在研究替代方案。)
谢谢大家。
只是为了确保人们理解它,这里是一个例子。
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function test(event) {
var X = window.event ? window.event.screenX : event.clientX;
// IE only because event.clientX for FF = fail.
if (X == null) {
alert("No X");
return;
}
};
</script>
</head>
<body onbeforeunload="test(event);">
so the onbeforeunload event doesn't have mouse information, so how do I get mouse XY? I am trying to know if the user clicked the close buttom on the browser to log them out right away (20minutes of session is too long for resource, but, we will not shorten it to make customer angry).
On IE, I can simply access mouse info to figure out if the user clicked close buttom or not during the onbeforeunload. For FF, I am suppose to use the parameterized event, which sadly has no mouse info at all.
(Note, this is not needed if there is a REAL onBrowserClose event. Since this is not the case, I am working on the alternatives.)
Thank you all.
Just to make sure people understand it, here is example.
<head runat="server">
<title>Untitled Page</title>
<script type="text/javascript">
function test(event) {
var X = window.event ? window.event.screenX : event.clientX;
// IE only because event.clientX for FF = fail.
if (X == null) {
alert("No X");
return;
}
};
</script>
</head>
<body onbeforeunload="test(event);">
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将鼠标移动填充到 mousemove 事件的变量中,然后在 onbeforeunload 事件中使用这些变量...
You could populate the mouse movement into variables on the mousemove event, and then use those variables in the onbeforeunload event...