Skip to content

Instantly share code, notes, and snippets.

@vinayakhumberi
Forked from CharlyJazz/XMLHttpRequest.js
Created March 11, 2020 15:01
Show Gist options
  • Save vinayakhumberi/8a52a5daea812edc3a163449b110aa7e to your computer and use it in GitHub Desktop.
Save vinayakhumberi/8a52a5daea812edc3a163449b110aa7e 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