当 Firefox 鼠标事件不存在时,在 onbeforeunload 上获取它?

发布于 2024-09-16 00:18:03 字数 759 浏览 9 评论 0原文

所以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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

森末i 2024-09-23 00:18:03

您可以将鼠标移动填充到 mousemove 事件的变量中,然后在 onbeforeunload 事件中使用这些变量...

<head runat="server">
    <title>Untitled Page</title>
<script type="text/javascript">
    var X = 0;

    function MouseMoveHandler(event) {
        X = window.event ? window.event.screenX : event.clientX;

        // IE only because event.clientX for FF = fail.
        if (X == null) {
            alert("No X");
            return;
        }
    };

    function BeforeUnloadHandler() {
        alert(X);
    }
</script>

</head>
<body onbeforeunload="BeforeUnloadHandler();" onmousemove="MouseMoveHandler(event);">

You could populate the mouse movement into variables on the mousemove event, and then use those variables in the onbeforeunload event...

<head runat="server">
    <title>Untitled Page</title>
<script type="text/javascript">
    var X = 0;

    function MouseMoveHandler(event) {
        X = window.event ? window.event.screenX : event.clientX;

        // IE only because event.clientX for FF = fail.
        if (X == null) {
            alert("No X");
            return;
        }
    };

    function BeforeUnloadHandler() {
        alert(X);
    }
</script>

</head>
<body onbeforeunload="BeforeUnloadHandler();" onmousemove="MouseMoveHandler(event);">
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文