Editing the <head> section with javascript

I would like to clear the entire head section after loading the page ... in fact, my goal would be to remove all the JavaScript code contained in the head section.

Is there a way to do something like this:

 document.head.innerHTML = ""; 

Explanation: I am using a Python script that uses Qt and webkit to take screenshots of websites.
It works on most styles, but there is one that it can't handle. There is a ton of JavaScript code on this site that works on timeouts. The WebKit webpage object allows you to execute JavaScript on the page. If there is some way that JavaScript removes the entire form of code in the section of the chapter, I would like to try this for testing to see if it allows my screenshot of the script.

+6
javascript html
source share
5 answers

You can remove items from the head, but that doesn't matter. Scripts are already running and deleting items does not unload them or anything else.

+3
source share
 document.getElementsByTagName("head")[0].innerHTML = ""; // IE var htmlEl = document.getElementsByTagName("html")[0]; htmlEl.removeChild(document.getElementsByTagName("head")[0]) var el = document.createElement("head"); htmlEl.appendChild(el); 

To stop the JavaScript scripts running setTimeout, you must use clearTimeout, but for this you must have a handler ... But you are lucky if they are defined as global variables.

+2
source share

Try using:

 document.getElementsByTagName('head').innerHTML = ""; 

to clear my head. document.head does not exist, so this may not work.

But you can try disabling JavaScript using JavaScript, as suggested by noah.

See http://www.manticmoo.com/articles/jeff/programming/javascript/removing-javascript-with-javascript.php for routes. It sounds crazy, but obviously it works.

0
source share

As Noah said, simply removing the code from the head tag will not achieve anything. You must actually undo what the code does. For example, if you use setTimeout() to set the timeout code that you are complaining about, you need to use clearTimeout() to disable it.

0
source share

$ ('# identifier') is empty (). Worked very well.

0
source share

All Articles