Connecting Tech Pros Worldwide Forums | Help | Site Map

window.event.x

Member
 
Join Date: Feb 2008
Posts: 41
#1: Oct 14 '08
i m wrinting javascript. on button click i am calling a javascript function that returns (x,y) coordinate of point where i clicked.
i used
window.event.x and window.event.y

it works fine in IE but not in mozila ..why so
any solution
thnx

rnd me's Avatar
Expert
 
Join Date: Jun 2007
Location: Urbana IL
Posts: 411
#2: Oct 14 '08

re: window.event.x


#1- there is no window.event in firefox.
#2- there is no x property of an event object. try screenX instead.
Member
 
Join Date: Oct 2008
Location: USA
Posts: 55
#3: Oct 16 '08

re: window.event.x


Expand|Select|Wrap|Line Numbers
  1. mouseX=function(evt){
  2. return(evt?(evt.pageX?evt.pageX:evt.clientX):(window.event.pageX?window.event.pageX:window.event.clientX))+(document.documentElement.scrollLeft?document.documentElement.scrollLeft:document.body.scrollLeft)
  3. }
  4. mouseY=function(evt){
  5. return(evt?(evt.pageY?evt.pageY:evt.clientY):(window.event.pageY?window.event.pageY:window.event.clientY))+(document.documentElement.scrollTop?document.documentElement.scrollTop:document.body.scrollTop)
  6. }
Member
 
Join Date: Sep 2008
Posts: 93
#4: Oct 16 '08

re: window.event.x


Quote:

Originally Posted by rnd me

#1- there is no window.event in firefox.
#2- there is no x property of an event object. try screenX instead.

Sorry to say but there is window.event in the firefox I had done and executed the code.The code written above by zaphod42 will work fine instead of the browser's behaviour.

The second solution provided by you is ok.
rnd me's Avatar
Expert
 
Join Date: Jun 2007
Location: Urbana IL
Posts: 411
#5: Oct 16 '08

re: window.event.x


Quote:

Originally Posted by Rsmastermind

Sorry to say but there is window.event in the firefox I had done and executed the code.The code written above by zaphod42 will work fine instead of the browser's behaviour.

I can personally assure you there is no window.event in firefox (unless you create one).

yes the code does work fine. thats because the firefox part doesn't use window.event but the intrinsic event argument, in this case named evt.
i know it's confusing, so lets break it down:


in the code:
Expand|Select|Wrap|Line Numbers
  1.  mouseY=function(evt){
  2.  return(evt?(evt.pageY?evt.pageY:evt.clientY):(wind  ow.event
  3.  
it asks (evt?)
if yes ( an event object was passed to the function, as in firefox), it returns evt.pageY or evt.clientY.

if (evt?) results in no, it means no argument was passed, as in IE.
it then returns window.event.pageY or window.event.clientY

so to sum: ie uses the window.event part, and firefox uses the argument evt part.

i hope this helps shed some light on the two confusing event models.
acoder's Avatar
Site Moderator
 
Join Date: Nov 2006
Location: UK
Posts: 14,581
#6: Oct 16 '08

re: window.event.x


This similar code will be a little easier to understand.
Reply