/** * Created by chen on 2017/11/8. */ !function () { var Skip={}; //获取XMLHttpRequest对象(提供客户端同http服务器通讯的协议) Skip.getXmlHttpRequest=function (){ if ( window.XMLHttpRequest ) // 除了IE外的其它浏览器 return new XMLHttpRequest() ; else if ( window.ActiveXObject ) // IE return new ActiveXObject("MsXml2.XmlHttp") ; }, //导入内容 Skip.includeJsText =function (rootObject,jsText){ if ( rootObject != null ){ var oScript = document.createElement( "script" ); oScript.type = "text/javascript"; //oScript.id = sId; //oScript.src = fileUrl; //oScript.defer = true; oScript.text = jsText; rootObject.appendChild(oScript); //alert(oScript.text); } }, //导入文件 Skip.includeJsSrc =function (rootObject, fileUrl){ if ( rootObject != null ){ var oScript = document.createElement( "script" ); oScript.type = "text/javascript"; oScript.src = fileUrl; rootObject.appendChild(oScript); } }, //同步加载 Skip.addJs=function(rootObject, url){ var oXmlHttp = Skip.getXmlHttpRequest() ; oXmlHttp.onreadystatechange = function(){//其实当在第二次调用导入js时,因为在浏览器当中存在这个*.js文件了,它就不在访问服务器,也就不在执行这个方法了,这个方法也只有设置成异步时才用到 if ( oXmlHttp.readyState == 4 ){ //当执行完成以后(返回了响应)所要执行的 if ( oXmlHttp.status == 200 || oXmlHttp.status == 304 ){ //200有读取对应的url文件,404表示不存在这个文件 Skip.includeJsSrc( rootObject, url); } else{ // alert( 'XML request error: ' + oXmlHttp.statusText + ' (' + oXmlHttp.status + ')' ) ; } } } oXmlHttp.open('GET', url, false); oXmlHttp.send(null); Skip.includeJsText(rootObject,oXmlHttp.responseText); } var rootObject=document.head,url=""; if($api.getStorage("languages")){ switch ($api.getStorage("languages")){ case "cn": url="language/cn.js"; break; case "en": url="language/en.js"; break; } }else { if (navigator.language.toLowerCase() == "zh-cn") { url="language/cn.js"; } else if (navigator.language.toLowerCase() == "en-us") { url="language/en.js"; }else { url="language/cn.js"; } } if(document.head.getElementsByTagName("title")[0].innerText!="运力集"){ url= "../"+url; } Skip.addJs(rootObject,url) }()