javascript - Dynamically Remove Script file from html page -
i developed website on navigate different html page home page calling load function following:
$("#content").load('page.html', function (response, status) {});
page.html contains script file loaded in home page. trying removing script file dynamically when navigate different page that
$("#content").load('another_page.html', function (response, status) { if (status = "success") { //remove script file in page.html } });
this following process have applied found google
function removejscssfile(filename, filetype) { var targetelement = (filetype == "js") ? "script" : (filetype == "css") ? "link" : "none" //determine element type create nodelist var targetattr = (filetype == "js") ? "src" : (filetype == "css") ? "href" : "none" //determine corresponding attribute test var allsuspects = document.getelementsbytagname(targetelement) (var = allsuspects.length; >= 0; i--) { //search backwards within nodelist matching elements remove if (allsuspects[i] && allsuspects[i].getattribute(targetattr) != null && allsuspects[i].getattribute(targetattr).indexof(filename) != -1) allsuspects[i].parentnode.removechild(allsuspects[i]) //remove element calling parentnode.removechild() } }
but script file still exist.
deleting script tag or removing js file tag won't discard js. still loaded. need tell him erase code.
one possible way encapsulate javascipt file 1 function, , redefine function. example :
function foo(){ //your javascript here }
and :
foo= function(){};
but if function contains event, still have unbind them manually.
Comments
Post a Comment