js动态加载以及确定加载完成的代码_javascript技巧

WBOY
Release: 2016-05-16 18:04:07
Original
1006 people have browsed it

代码如下:

复制代码代码如下:

var otherJScipt = document.createElement("script");
otherJScipt = document.createElement("script");
otherJScipt.setAttribute("type", "text/javascript");
otherJScipt.setAttribute("src", "/xxx.js");
document.getElementsByTagName("head")[0].appendChild(otherJScipt);//追加到head标签内


//判断服务器
if (navigator.userAgent.indexOf("IE") >= 0) {
//IE下的事件
otherJScipt.onreadystatechange = function () {
//IE下的判断,判断是否加载完成
if (otherJScipt && (otherJScipt.readyState == "loaded" || otherJScipt.readyState == "complete")) {
otherJScipt.onreadystatechange = null;
callMyFun();
}
};
}
else {
otherJScipt.onload = function () {
otherJScipt.onload = null;
callMyFun();
};
}
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!