Created
June 29, 2022 02:22
-
-
Save yeyuguo/aef7b91207ec315e0ca8328f6e402fe1 to your computer and use it in GitHub Desktop.
用于加载 script 资源测试库
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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