Mouse position - Cross browser compatibility

Viewed 5667

Working with the mouse within Javascript I have occasionally met the following event attributes:

  • clientX, clientY
  • layerX, layerY
  • offsetX, offsetY
  • pageX, pageY
  • screenX, screenY
  • x, y

I'm wondering what their cross-browser compatibility looks like in general, as I have only found bits and pieces of info that I'm trying to patch up together.

2 Answers

You should only rely on client*, movement*, screen*. In MDN Web docs, their compatibility is unknown in most major browsers but they should be considered as support (otherwise, jQuery would be broken in many cases).

page* are not supported in Firefox, but they can be calculated from the above properties. Here is the link to the jQuery implementation.

Other properties, offset*, x, y, layer* are not standard and you should stop using them if you want to write a high compatibility-level code.

I also made a blog post to summarize all dimensional or position-related properties/methods in Javascript here. Anyone can take a look to see if it is helpful.

Related