1

我有在 IE 中工作但在 Firefox 和 chrome 中没有的编码...

 function handleWindowClose() {
            if ((window.event.clientX < 0) || (window.event.clientY < 0))
             {
                 event.returnValue = "Are You sure to leave this page";
             }
         }
         window.onbeforeunload = handleWindowClose;

谁能帮我...

4

2 回答 2

8

window.event是一个只有 IE 的东西。要让它在其他浏览器中工作,您必须将事件作为处理函数的参数:

function handleWindowClose(e) {
    e = window.event || e; 
        if ((e.clientX < 0) || (e.clientY < 0))
        {
            e.returnValue = "Are You sure to leave this page";
        }
}
window.onbeforeunload = handleWindowClose;
于 2012-04-06T16:21:54.363 回答
1

也许只是添加将鼠标位置存储在变量中的 mousemove 处理程序

var mouse;
function storeMouse(e)
{
    if(!e) e = window.event;
    mouse = {clientX: e.clientX, clientX:e.clientY};
}
function test(e){
     alert(mouse.clientX);
}

并使用jQuery?

  $(window).bind('beforeunload', function() {
    if (iWantTo) {
        return 'Are You sure to leave this page';
    }
}); 
于 2012-04-06T15:25:49.870 回答