Posts: 370
Threads:46
Joined: Oct 2011
Reputation:
7
Disabling JavaScript event selectively in Browsers
I was doing an experiment on browsers. It needs to disable OnBlur() event of JavaScript. Can there be any means to selectively enable/disable JS events?
Louis
Master of the IRCs!


Posts: 153
Threads:23
Joined: May 2012
Reputation:
11
RE: Disabling JavaScript event selectively in Browsers
I don't think it's actually possible. The only method I can think of is selecting all elements that have onblur attached and then overwriting it or maybe nooping onblur for ALL elements.
Code:
[].forEach.call(document.getElementsByTagName("*"),function (elm) {
elm.onblur = function(e){ e.preventDefault(); }; // Prevent the default onblur actions?
});
This code is untested however.
EDIT: If you want, I could possibly create a small(ish?) lib to disable things similar to this method besides just onblur.
This post was last modified: 10-31-2014, 04:16 PM by
Louis.
Posts: 9,733
Threads:1,026
Joined: Jun 2011
Reputation:
76
RE: Disabling JavaScript event selectively in Browsers
Posts: 370
Threads:46
Joined: Oct 2011
Reputation:
7
RE: Disabling JavaScript event selectively in Browsers
Can't there be any such plugin which can rewrite site's Javascript code dynamically?
Louis
Master of the IRCs!


Posts: 153
Threads:23
Joined: May 2012
Reputation:
11
RE: Disabling JavaScript event selectively in Browsers
Yyyeeeaaaa... no. Using code to rewrite code is definitely not the way to go. There is no way to disable pieces of code like that. You can only reset DOM elements and the like. Itd be insanely complicated to edit out parts you dont want as code can change. Better off doing it the way i suggested.