簡體   English   中英

Event.ClientX 在 firefox 和 chrome 中不工作

[英]Event.ClientX is not working in firefox and chrome

我的編碼在 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;

誰能幫我...

window.event僅適用於 IE。 要讓它在其他瀏覽器中工作,您必須將事件作為處理程序 function 的參數獲取:

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;

也許只是添加將鼠標 position 存儲在變量中的 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';
    }
}); 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM