I want to determine if the script tag is loaded (which was dynamically created and added to the DOM). The onerror event fires, with the exception of files: // URL in Firefox.
Unfortunately, none of the methods described here (with the exception of timeouts, which are unacceptable in my case) seem to work in Firefox if the src tag of the script file is: // URL (or the relative URL and page were loaded through the file: // url)
Test case:
var script = document.createElement('script'); script.setAttribute('type', 'text/javascript'); script.setAttribute('src', 'doesnotexist.js'); script.onerror = function() { alert("Loading failed!"); } document.getElementsByTagName('head')[0].appendChild(script);
Upload this to the HTML page with the file: // URL. The onerror event will not be fired in Firefox. Download from a web server or in Safari or Chrome and it will.
This seems like a mistake to me. Is there any known way around it?
javascript firefox
tlrobinson
source share