I developed a website on which i navigate different html page from home page by calling load function like the following:
$("#content").load('page.html', function (response, status) {});
page.html contains some script file which also loaded in home page. What i am trying do is removing the script file dynamically when i navigate different page like that
$("#content").load('another_page.html', function (response, status) {
if (status = "success") {
//Remove script file in page.html
}
});
This following process i have applied found by google
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()
}
}
but the script file still exist.
undefined.