Detect mousemove when over an iframe?

Charles Zink picture Charles Zink · Apr 13, 2011 · Viewed 46.6k times · Source

I have an iframe that takes up the entire window (100% wide, 100% high), and I need the main window to be able to detect when the mouse has been moved.

Already tried an onMouseMove attribute on the iframe and it obviously didn't work. Also tried wrapping the iframe in a div like so:

<div onmousemove="alert('justfortesting');"><iframe src="foo.bar"></iframe></div>

.. and it didn't work. Any suggestions?

Answer

Łukasz Jagodziński picture Łukasz Jagodziński · Aug 8, 2012

If your target isn't Opera 9 or lower and IE 9 or lower you can use css attribute pointer-events: none.

I found it the best way just to ignore iframe. I add class with this attribute to iframe in onMouseDown event and remove in onMouseUp event.

Works perfect for me.