Is there only a client-side method to determine if an xml file is hosted in another domain (404 response) or is accessible via Internet Explorer? CORS is not an option. I only care about its existence.
For Chrome and Firefox, there is only a client-side method, combining <script>tag insertion with callbacks for the download and error events. Below is the test code that I put in the browser console for Firefox and Chrome.
In Internet Explorer, the "readystatechange" event always fires regardless of whether the file exists or not. I looked at the returned object from the readystatechange callback, and I cannot find the difference between the response object from the existing file and the response object from the nonexistent file.
I also experimented with tag <img>and tag tag <iframe>, and the results are not as useful as pasting a tag <script>for any browser.
function loadFile(urlOfDocument) {
var element = document.createElement('script');
element.async = true;
element.onload = function() {
console.log("onload called");
}
element.onerror = function() {
console.log("onerror called");
}
element.onreadystatechange= function () {
console.log("onreadystatechange: ", element.readyState);
if (this.readyState == 'complete') {
console.log("loading complete");
}
}
element.src = urlOfDocument;
document.getElementsByTagName('head')[0].appendChild(element);
}
var urlOfDocument = "http://url.to.missing.file";
loadFile(urlOfDocument);
source
share