Ethical Hacker Tip: Dynamically Creating Script Tags with JavaScript

Listen to this Post

Featured Image
Here’s how to dynamically create a script tag using JavaScript:

(function () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://<hostname>/script.js";
document.getElementsByTagName("head")[bash].appendChild(script);
})();

This achieves the same result as:

<script src="https://<hostname>/script.js"></script>

Key Points:

  • Injects a `