How to load script files dynamically by JavaScript
Editor to share with you JavaScript how to dynamically load script files, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Dynamically load script files function appendscript (src, text, reload, charset) {
Var id = hash (src + text)
If (! reload & & in_array (id, evalscripts)) return
If (reload & & $(id)) {
$(id) [xss_clean] .removeChild ($(id))
}
Evalscripts.push (id)
Var scriptNode = document.createElement ("script")
ScriptNode.type = "text/javascript"
ScriptNode.id = id
ScriptNode.charset = charset
? Charset
: BROWSER.firefox
? Document.characterSet
: document.charset
Try {
If (src) {
ScriptNode.src = src
ScriptNode.false
ScriptNode. {
ScriptNode.true
JSLOADED [src] = 1
}
ScriptNode. {
If (
(scriptNode.readyState = = "loaded" | |
ScriptNode.readyState = = "complete") & &
! scriptNode.onloadDone
) {
ScriptNode.true
JSLOADED [src] = 1
}
}
} else if (text) {
ScriptNode.text = text
}
Document.getElementsByTagName ("head") [0] .appendChild (scriptNode)
} catch (e) {}
} these are all the contents of the article "how to dynamically load script files in JavaScript". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!