disable all click events on page (javascript)

后端 未结 8 1816
孤城傲影
孤城傲影 2020-12-13 15:11

Whats the easiest way to temporarily disable all mouse click/drag etc events through javascript?

I thought I could do document.onclick = function() { return fa

8条回答
  •  温柔的废话
    2020-12-13 15:29

    The winning answer works well, but if you had pass the capture true boolean value, at the moment you want to remove the listener, you have to pass the exact same value. Otherwise, the listener removal will not work.

    Example:

    listener addition

    document.addEventListener('click', DisableClickOnPage.handler, true);

    listener removal

    document.removeEventListener('click', DisableClickOnPage.handler, true);

    Doc: https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/removeEventListener

提交回复
热议问题