disable all javascript events on page

前端 未结 3 1727
耶瑟儿~
耶瑟儿~ 2021-01-22 14:46

I am trying to write a chrome extension that disables event listeners for all elements (mouseover, click, ...) I am not trying to rewrite noscript, this is just a setup step tha

相关标签:
3条回答
  • 2021-01-22 14:49

    If you have events made by jQuery as you say, it keeps around the data that you can parse out. You can see how the excellent Visual Events does it, as a more general solution (i.e. outside Chrome extensions).

    0 讨论(0)
  • 2021-01-22 15:02

    This is not a complete example, as I won't do all of your work for you, but might lead you in the right direction:

    function preventAll(){
      var dom = document.getElementsByTagName('*');
      var km = ['click', 'dblclick', 'mousedown', 'mousemove', 'mouseover', 'mouseout', 'mouseup', 'mouseenter', 'mouseleave', 'keydown', 'keypress', 'keyup'];
      for(var i=0,l=dom.length; i<l; i++){
        for(var n=0,c=km.length; n<c; n++){
          dom[i]['on'+km[n]] = function(e){
            e = e || event;
            e.preventDefault();
            return false;
          }
        }
      }
      var fr = frames;
      for(var i=0,l=fr.length; i<l; i++){
        // cancell frames events here
      }
    }
    
    0 讨论(0)
  • 2021-01-22 15:04

    It's not possible to intercept or list all previously-chained events in Javascript. However, it does look like Chrome plugins specifically (as opposed to the DOM in general) have an API for manipulating how Javascript works.

    0 讨论(0)
提交回复
热议问题