I'm trying to detect an XHR failing on mixed content. It looks like different browsers have different implementations:
var xhr = new XMLHttpRequest();
try {
xhr.open('http://otherdomain/');
} catch (err) {
console.log(err); // IE10 hits this one
}
try {
xhr.send(); // Chrome fails here, but doesn't throw an error
} catch (err) {
console.log(err); // No browser I've tried hits this one
}
I don't want to use autodetection (xhr.open('//otherdomain')
), since the target might not support http, or https. I simply want to know the call failed, so I can show an error in my page. Is it possible to handle this correctly for all browsers?