Catching Mixed Content Error

I am trying to detect XHR mismatch on mixed content. It seems that 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 do not want to use autodetection ( xhr.open('//otherdomain')), since the target may not support http or https. I just want to know that the call failed, so I can show an error on my page. Is it possible to handle this correctly for all browsers?

+4
source share
1 answer

javascript. , . , , , -, .

0

All Articles