mozilla的javascript格式

时间:2011-03-30 10:49:12

标签: javascript

在javascript中mozilla的window.event.clientX的等价物是什么? 这是我的代码,在body中调用的函数 - > onbeforeunload =“返回CloseOrNotClose(事件);”

这很好,但不适用于mozilla。

function CloseOrNotClose(event) {

var ie = document.all;
if (ie) {
           if ((window.event.clientX < 0) || (window.event.clientY < 0)) {
                    return "Your Information related to this exam will be lost and you will have to reappear for it, \nDo you want to continue?";
             }
}
else {
    if ((event.clientX < 0) || (event.clientY < 0)) 
    return "Your Information related to this exam will be lost and you will have to reappear for it, \nDo you want to continue?";
}

}

2 个答案:

答案 0 :(得分:2)

Internet Explorer有window.event.clientX

Mozilla:

function show_coords(event)
{
  var x = event.clientX;
  var y = event.clientY;
  alert("X coords: " + x + ", Y coords: " + y);
}

EDIT1:

  

在body中调用的函数 - &gt; onbeforeunload =“return CloseOrNotClose(event);”

我认为它仅适用于Mozilla window.onbeforeunload = CloseOrNotClose;

EDIT2:

  

请注意,在Firefox 4及更高版本中,返回的字符串不会显示给用户。

请参阅https://developer.mozilla.org/en/DOM/window.onbeforeunload

答案 1 :(得分:0)

你能展示你一直在使用的所有功能吗?

这对我有用:

function getXY(e)
{
  var e=(!e) ? window.event : e;
  var X = 0;
  var Y = 0;

  if(e.pageX)
  {
    X = e.pageX + window.pageXOffset;
    Y = e.pageY + window.pageYOffset;
  }