Created
July 9, 2015 20:02
-
-
Save fstamour/4f1617f2c6194241e420 to your computer and use it in GitHub Desktop.
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 loadJS(src, retryP, delay) { | |
try { | |
var scriptTag = document.createElement('script'); | |
scriptTag.type = 'text/javascript'; | |
scriptTag.src = src; | |
var fail = function (event) { | |
console.error("Unable to load the script: '" + src + "'"); | |
if (retryP) { | |
window.setTimeout(function () { | |
loadJS(src, retryP, delay); | |
}, (typeof delay == 'number') ? delay : 1); | |
} | |
} | |
scriptTag.addEventListener('error', fail, false); | |
var headTag = document.getElementsByTagName('head')[0]; | |
headTag.appendChild(scriptTag); | |
} catch (e) { | |
console.error("An error occurred while trying to lunch the loading of the script: ", src); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment