Detects loading failure of injected script tags for IE, FF, Webkit and Opera.
- Webkit & FF rely on the onerror handler
- Opera on an inline script right after the injected tag (like ScriptCommunicator)
- IE uses a trick I found that allows to load a script as an event handler for a DOM element, so I load the script as the onclick event of the script tag itself then controls if the onclick method exists and .call( window ) it if it does.
There are probably some quirks here and there: apart from the fact the code is not that well-written and still contains some console.log, it would need better feature detection and the behaviour of scripts called as an onclick method under IE should be checked more thoroughly.
But the biggest problem is inconsistency when it comes to scripts that *are* loaded but can't be parsed. Thing is the trick for IE & Opera makes it so such faulty scripts will fire errors but NOT under FF & Webkit.
"Nevermind", I told myself, let's listen to the error event on the window element and bring some consistency there. I made it work for FF, but Webkit guys apparently don't feel us worthy of being notified when there's an error in such a case:
https://bugs.webkit.org/show_bug.cgi?id=8519. This bug has been opened for *4* years and the comments from some of the webkit devs just proved to me, once again, that devs never eat their own dog food. Particularly enjoyed the guy suggesting to properly use try/catch bocks or the other one thinking we need yet-another-browser-specific solution.
Anyway, that's about as far as I'll go for now. What we have is an error notification if a script couldn't be loaded BUT at the cost of an inconsistency: an error will be notified when the script has been loaded but cannot be parsed under Opera and IE (and FF with a window "error" listener).
I leave it to John to decide if the inconsistencies are acceptable in that case.