views:

1188

answers:

2

In trying to convert some of my JS to cross-browser compatibility, I've come across strange behaviour where I'm unable pinpoint the problem.

I want to convert window.event.x (IE specific) using jQuery, so my code looks as follows:

function someFunction(e){
   var ev = $.event.fix(e);
   alert(ev.pageX);
}

This returns the correct value in IE, however in FF it's returning an eight-digit number. Any clues?

A: 

At least on my local XP VM, both Firefox and IE 8 return the same reasonable value for the X/Y coords when using Javascript like this:

$('#some-big-div').click(function(e) {
  console.log("mouse coords: (" + e.pageX + ", " + e.pageY ")")
}

Perhaps the call to $.event.fix() in your example is b0rking the FF output?

rcoder
Thanks for the response. It seems this isn't necessarily a jQuery issue but rather somethign specific to FF? When checking firebug for the event obj, it shows the same massive #.
abstract_a
A: 

Make sure you're using the most up to date version of jQuery. On the official site, it states that event.pageX and event.pageY have been fixed for IE, so you may not need to use fix();

idrumgood
Thanks for the response. I'm using the latest v of jQuery and even without fix() it returns inconsistent values. Checking the event object through firebug also shows the same eight digit number so it's certainly not the jQuery call.
abstract_a