By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,851 Members | 1,097 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,851 IT Pros & Developers. It's quick & easy.

window.event.x

P: 41
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
Oct 14 '08 #1
Share this Question
Share on Google+
5 Replies


rnd me
Expert 100+
P: 427
#1- there is no window.event in firefox.
#2- there is no x property of an event object. try screenX instead.
Oct 14 '08 #2

P: 55
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. }
Oct 16 '08 #3

P: 93
#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.
Oct 16 '08 #4

rnd me
Expert 100+
P: 427
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.
Oct 16 '08 #5

acoder
Expert Mod 15k+
P: 16,027
This similar code will be a little easier to understand.
Oct 16 '08 #6

Post your reply

Sign in to post your reply or Sign up for a free account.