I would like to clear the entire head
section once the page loads... actually, my goal would be to delete all JavaScript code held in the head
section.
Is there some 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 websits.
It works on most sties, but there is one that it fails on. That site has a bunch of JavaScript code that it runs on timeouts. The WebKit webpage object allows me to execute JavaScript on the page. If there is some way to have the JavaScript remove all of the code form the head section I'd like to be able to try that for testing purposes to see if it resolves my screenshot script issue.
JavaScript in body or head: Scripts can be placed inside the body or the head section of an HTML page or inside both head and body.
Hover over your content and click Edit. In the content editor, click the Settings tab, then click Advanced options. In the Additional code snippets section, enter your code snippet into the Head HTML or Footer HTML field.
The <head> HTML element contains machine-readable information (metadata) about the document, like its title, scripts, and style sheets.
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 JavaScript scripts running by setTimeout, you should use clearTimeout, but for this case you should have a handler... But you're lucky, if they are defined as global variables.
You can remove elements from the head, but it wont matter. The scripts have already run and removing the elements wont unload them or anything.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With