Skip to content

Instantly share code, notes, and snippets.

@CharlyJazz
Last active May 17, 2023 08:13
Show Gist options
  • Save CharlyJazz/edd281193f334264eb41e809b581f749 to your computer and use it in GitHub Desktop.
Save CharlyJazz/edd281193f334264eb41e809b581f749 to your computer and use it in GitHub Desktop.
XMLHttpRequest injection load javascript script.
//Before </body> tag
<script>
var xhr = new XMLHttpRequest();
xhr.open("get", "cookbook.js", true);
xhr.onreadystatechange = function () {
if (xhr.readyState == 4) {
if (xhr.status >= 200 && xhr.status < 300 || xhr.status == 304) {
var script = document.createElement("script");
script.type = "text/javascript";
script.text = xhr.responseText;
document.body.appendChild(script);
}
}
};
xhr.send(null);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment