2012-04-06 161 views
0

工作,我有编码它在IE而不是在火狐和Chrome的工作...Event.ClientX没有在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; 

谁能帮我...

+0

退房:http://stackoverflow.com/questions/2116177/windows-event-is- undefined-javascript-error-in-firefox – 2012-04-06 15:13:29

回答

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'; 
    } 
}); 
9

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; 
+0

window.event也支持chrome safari和opera。 – Charles 2014-10-09 08:00:53

+1

如果您正在定位一个项目,请不要忘记添加窗口scrollLeft和窗口scrollTop。 – Szabi 2014-11-04 15:29:09

相关问题