Detect mousemove when over an iframe?

后端 未结 11 576
Happy的楠姐
Happy的楠姐 2020-11-29 05:47

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

11条回答
  •  再見小時候
    2020-11-29 06:40

    On your "parent" frame, select your "child" iframe and detect the event you are interested, in your case mousemove

    This an example of code to be used in your "parent" frame

    document.getElementById('yourIFrameHere').contentDocument.addEventListener('mousemove', function (event) {
                    console.log(, event.pageX, event.pageY, event.target.id);
                }.bind(this));
    

提交回复
热议问题