Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

google chrome - disable all javascript events on page

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 that i need.

I have tried $("body *).unbind() and .unbind("mouseover click") and .off() and .off("mouseover click") none worked.

What am i doing wrong?

PS: it would also be fine to just disable all javascript code (coming from the page itself) from running on the page and only allow my extension injected code

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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
  }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...