Crossbrowser Mouse Click Position


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your 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. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.