I have code to get x-y coordinates when the browser scrolls:
left1 = window.event.clientX + document.body.scrollLeft + document.documentElement.scrollLeft;
top1 = window.event.clientY + document.body.scrollTop + document.documentElement.scrollTop;
This is working in IE7, but not in Mozilla Firefox 3.5.19. How can I get it working in Firefox?
Remember that the click event is handled differently in Mozilla than it is in internet explorer. Also they hold different ways of attaining the position of the cursor location. This is a very easy google search to get the specifics on either.
var IE = document.all ? true : false; // check to see if you're using IE
if (IE) //do if internet explorer
{
cursorX = event.clientX + document.body.scrollLeft;
cursorY = event.clientY + document.body.scrollTop;
}
else //do for all other browsers
{
cursorX = (window.Event) ? e.pageX : event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
cursorY = (window.Event) ? e.pageY : event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
}
Also note that you should have something like the following in your initialization code:
if (window.Event) {
if (window.captureEvents) { //doesn't run if IE
document.captureEvents(Event.MOUSEMOVE);
}
}
document.onmousemove = refreshCursorXY;
On the click side of things as I said there is differences in what value the click is attributed between browsers. For example, this check should happen in your click event (that you send e, the event, to). e will not be sent by I.E. so we do it like so:
//internet explorer doesn't pass object event, so check it...
if (e == null)
{
e = window.event;
}
//1 = internet explorer || 0 = firefox
if ((e.button == 1 && window.event != null || e.button == 0))
And again, there are many differences between IE and other browsers, thus there is much documentation. Google searches can do wonders if you require further information on the subject.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With