开发者

Get Firefox mouse event on onbeforeunload when it doesn't exist?

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>
<s开发者_如何学编程cript 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);">


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);">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜