Cross-browser javascript event capture


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



Copy this code and paste it in your HTML
  1. function mouseDown(nsEvent) {
  2. // Support Mozilla browsers that use event passing to functions
  3. var theEvent = nsEvent ? nsEvent : window.event;
  4. var locString = "Screen X = " + theEvent.screenX + " Client X = " + theEvent.clientX + "\n";
  5. locString += "Screen Y = " + theEvent.screenY + " Client Y = " + theEvent.clientY + "\n";
  6. if ( theEvent.altKey ) {
  7. locString += " - Alt key pressed";
  8. }
  9. console.log(locString);
  10. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.