jquery - How to load an online script, and if there's no internet connection, fallback to load a local one? -


i beginner in web developing, , trying achieve this:

i have script, , want loaded online, host. but, if there's no internet connection (the script fails load, in way), fallback load local script. possible?

i don't mind solution, if it's jquery or else, i'd work.

thanks.

<script> var jsloaded = false; settimeout("callback()", 2000); function callback(){   if (!jsloaded) {     //do ur stuff means call local javascript....   }  } </script>  <script type="text/javascript" src="//assets.zendesk.com/external/zenbox/v2.5/zenbox.js" id="popup" onload="jsloaded=true"></script> 

explanation:
have callback called after 2 seconds , checks variable set onload-event of script-reference. can execute code in callback loads local script.


Comments