Posted By

delikassap on 10/13/10


Tagged

crossbrowser click mouse position


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

nbehier
NyX


Crossbrowser Mouse Click Position


 / Published in: JavaScript
 

URL: http://www.quirksmode.org/js/events_properties.html

  1. function FindPosition(e) {
  2. var posx = 0;
  3. var posy = 0;
  4. if (!e) var e = window.event;
  5. if (e.pageX || e.pageY) {
  6. posx = e.pageX;
  7. posy = e.pageY;
  8. }
  9. else if (e.clientX || e.clientY) {
  10. posx = e.clientX + document.body.scrollLeft
  11. + document.documentElement.scrollLeft;
  12. posy = e.clientY + document.body.scrollTop
  13. + document.documentElement.scrollTop;
  14. }
  15. // posx and posy contain the mouse position relative to the document
  16. // Do something with this information
  17. }

Report this snippet  

You need to login to post a comment.