Skip to content

Instantly share code, notes, and snippets.

@rtroe
Created April 2, 2018 11:03
Show Gist options
  • Save rtroe/2f9397a28ef2f8703f16c4a73cf8990e to your computer and use it in GitHub Desktop.
Save rtroe/2f9397a28ef2f8703f16c4a73cf8990e to your computer and use it in GitHub Desktop.
window.onload = function() {
}
function removejscssfile(filename, filetype){
var targetelement=(filetype=="js")? "script" : (filetype=="css")? "link" : "none" //determine element type to create nodelist from
var targetattr=(filetype=="js")? "src" : (filetype=="css")? "href" : "none" //determine corresponding attribute to test for
var allsuspects=document.getElementsByTagName(targetelement)
for (var i=allsuspects.length; i>=0; i--){ //search backwards within nodelist for matching elements to remove
if (allsuspects[i] && allsuspects[i].getAttribute(targetattr)!=null && allsuspects[i].getAttribute(targetattr).indexOf(filename)!=-1)
allsuspects[i].parentNode.removeChild(allsuspects[i]) //remove element by calling parentNode.removeChild()
}
}
function OnLoad(){
var script = document.createElement('script');
script.onload = function () {
console.log("Script Loaded");
loadFile();
removejscssfile("js/load.js", "js");
loadFile();
};
script.src = "js/load.js";
document.head.appendChild(script); //or something of the likes
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment