Skip to content

Instantly share code, notes, and snippets.

@arcesino
Created April 3, 2014 17:46
Show Gist options
  • Save arcesino/9959197 to your computer and use it in GitHub Desktop.
Save arcesino/9959197 to your computer and use it in GitHub Desktop.
To load a script file with great cross-browser support
loadScript = (src, callback) ->
script = document.createElement("script")
loaded = undefined
script.setAttribute "type", "text/javascript"
script.setAttribute "src", src
if script.readyState
script.onreadystatechange = -> # For old versions of IE
callback() if @readyState is "complete" or @readyState is "loaded"
return
else # Other browsers
script.onload = callback
(document.getElementsByTagName("head")[0] or document.documentElement).appendChild script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment