Skip to content

Instantly share code, notes, and snippets.

@yeyuguo
Created June 29, 2022 02:22
Show Gist options
  • Save yeyuguo/aef7b91207ec315e0ca8328f6e402fe1 to your computer and use it in GitHub Desktop.
Save yeyuguo/aef7b91207ec315e0ca8328f6e402fe1 to your computer and use it in GitHub Desktop.
用于加载 script 资源测试库
function loadScript(url, callback) {
try {
let script = document.createElement("script");
if (script.readyState) {
// IE
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);
} catch (error) {
console.log("error: ", error);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment