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?
There is no way to handle this error with javascript unfortunately. It is a security restriction enforced by the browser and thrown on a lower level. I have tried so many different methods, including the use of extensions but nothing worked except a timeout handler to be honest.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With