Assuming jQuery (maybe it will work with this too?), Is not such a simple solution as: element.innerHTML = element.innerHTML; ?
I. Set the textual representation of everything that node contains as the current textual representation of everything that is contained in node. Text assignments like this nuke, all / all handlers are associated with element.addEventListener . You can also use element.removeAttribute('inlineEventName') for nuke in the html file itself.
You can simply install .innerHTML or .outerHTML as a copy of what you already have, and then skip the array of handler names and call .removeAttribute again. Iterate through the child nodes of any target and again (this time for each element) loop through an array of media names that you would like to kill. Perhaps there is a way to iterate over the list of handler names, I donβt know - I would just create an array of all of them that find and pass through this array, nuking as necessary. You would remove all JS-related handlers at the initial replacement, then you will need to remove the built-in handlers for node and all / all children.
Here is a quick example that disables everything in the body and its children. You will notice that the first time a βkillβ notification fires twice β once from the built-in handler and once from the js handler. The second time the notification only works once. This time from the built-in handler. Try removing it or using .removeAttribute , as I suggested earlier, to use this handler.
<!DOCTYPE html> <html> <head> <script> function byId(e){return document.getElementById(e);} window.addEventListener('load', onDocLoaded, false); function onDocLoaded() { byId('mFileInput').addEventListener('change', onFileChosen, false); byId('mBtn').addEventListener('click', killPageJs, false); } function killPageJs(evt) { alert('killed'); document.body.innerHTML = document.body.innerHTML; } </script> <style> </style> </head> <body> <button id='mBtn' onclick='killPageJs();'>Kill</button><hr> <input id='mFileInput' type='file'/><br> <img id='tgt' /> </body> </html>
source share