Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get over a blocked event?

I’m developing an JavaScript app which needs to trigger mousemove event, and I am using tampermonkey to "embed" it on websites to test if it works on them. On one website, the mousemove event is simply blocked (I don’t know why) and even console.log within this event doesn’t show. It seems like this event has never triggered (the website ignores).

Is it possible to "override" events and block them? If so, how can I override this action and enable my specific mousemove event?

This script won’t work:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

document.addEventListener("mousemove", function(e) {
    e = e || window.event;
    e.stopPropagation();
    console.log("[HELLO] Is it moving?!");
}, false);

(the result will be… nothing. this won’t be logged)

Update They set window.onmousemove as null. Is there any way to revert this?

>Solution :

If you can run your code before theirs, you can save the function

window.onmousemove = function()  {
  console.log("moving",new Date())
};
window.myMove = window.onmousemove;
document.getElementById("x").addEventListener("click",function() {
  window.onmousemove=null
})

document.getElementById("y").addEventListener("click",function() {
  window.onmousemove=myMove;
})
<button type="button" id="x">Turn off mousemove</button>
<button type="button" id="y">Turn mousemove back on</button>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading