I am experimenting with JavaScript & I can’t seem to understand simple behavior. What I want to do, is to disable absolutely any JS that was before the following code snippet:
void (function(){
(function prepare(name){
var elements = document.getElementsByTagName(name);
for(var i = elements.length; i--;)
elements[i].parentNode.removeChild(elements[i]);
return prepare;
}('script'));
}());
NOTE Marcel Korpel: indenting inserted for readability, but you should paste this as one line-of-code in the address bar.
The following code theoretically should disabled all the JS on the page, right? To test it, you can execute it via javascript: [..] when the page is fully loaded. FireBug HTML will show that all scripts are removed. However, there were things in code like setTimeout, setInterval, binding specific actions, on click events, etc. and they still work even after the code is executed.
Is there a way to completely remove all of this after the script is executed?
Unfortunately, timeouts (as in
setTimeout) and intervals (setInterval) are opaque. This means there is no way to cancel running timeout/interval w/o knowing its handle. Same is for event listeners, DOM object’s event sink is not available, so no way toremoveEventListenerwithout knowledge howaddEventListenerwas called.The only way i can figure out is user javascript in Opera, where you can hook functions listed above and keep track of timeouts/intervals/listeners.