Quantcast
Channel: 懒得折腾
Viewing all articles
Browse latest Browse all 764

JavaScript and CSS dynamic loading

$
0
0
globalConfig.loadCSS = globalConfig.loadCSS || function(filename){
	var fileref=document.createElement("link");
	fileref.setAttribute("rel", "stylesheet");
	fileref.setAttribute("type", "text/css");
	fileref.setAttribute("href", filename);
	document.getElementsByTagName("head")[0].appendChild(fileref);
};

globalConfig.loadScript = globalConfig.loadScript || function(url, callback){
	var script = document.createElement('script');
	script.type = "text/javascript";
	if(script.readyState){
		script.onreadystatechange = function(){
			if(script.readyState === "loaded" || script.readyState === "complete"){
				script.onreadystatechange = null;
				callback();
			}
		};
	}else{
		script.onload = function(){
			callback();
		};
	}	
	script.src = url;
	document.getElementsByTagName("head")[0].appendChild(script);
};


Viewing all articles
Browse latest Browse all 764

Trending Articles