Code:loadScript( )加载js的功能函数
2018-09-24 21:42
复制代码 代码如下:
<scripttype=text/javascript>
/**
*functionloadScript
*Copyright(C)2006DaoGottwald
*
*Thislibraryisfreesoftware;youcanredistributeitand/or
*modifyitunderthetermsoftheGNULesserGeneralPublic
*LicenseaspublishedbytheFreeSoftwareFoundation;either
*version2.1oftheLicense,or(atyouroption)anylaterversion.
*
*Thislibraryisdistributedinthehopethatitwillbeuseful,
*butWITHOUTANYWARRANTY;withouteventheimpliedwarrantyof
*MERCHANTABILITYorFITNESSFORAPARTICULARPURPOSE.SeetheGNU
*LesserGeneralPublicLicenseformoredetails.
*
*YoushouldhavereceivedacopyoftheGNULesserGeneralPublic
*Licensealongwiththislibrary;ifnot,writetotheFreeSoftware
*Foundation,Inc.,51FranklinStreet,FifthFloor,Boston,MA02110-1301USA
*
*Contactinformation:
*DaoGottwald<daoatdesign-noir.de>
*Herltestra?e12
*D-01307,Germany
*
*@version1.5
*@url
*/
functionloadScript(url,callback){
varscript=document.createElement(script);
script.type=text/javascript;
/*shouldbeapplication/javascript
*
*
*/
if(callback)
script.onload=script.onreadystatechange=function(){
if(script.readyState&&script.readyState!=loaded&&script.readyState!=complete)
return;
script.onreadystatechange=script.onload=null;
callback();
};
script.src=url;
document.getElementsByTagName(head)[0].appendChild(script);
}
</script>
实例:
复制代码 代码如下:<scripttype=text/javascript>
//preventgoogleanalyticsfromslowingdownpageloading
window.addEventListener(load,function(){
loadScript(
window._uacct=UA-xxxxxx-x;
urchinTracker();
});
},false);
</script>
上一篇:FCK调用方法..