I\'ve been doing a lot of research and could not find a way to handle this. I\'m trying to perform a jQuery ajax call from an https server to a locahost https server running
As of now: There is no way to differentiate this event between browers. As the browsers do not provide an event for developers to access. (July 2015)
This answer merely seeks to provide ideas for a potential, albiet hacky and incomplete, solution.
Disclaimer: this answer is incomplete as it doesn't completely solve OP's issues (due to cross-origin policies). However the idea itself does has some merit that is further expanded upon by: @artur grzesiak here, using a proxy and ajax.
After quite a bit of research myself, there doesn't seem to be any form of error checking for the difference between connection refused and an insecure response, at least as far as javascript providing a response for the difference between the two.
The general consensus of my research being that SSL certificates are handled by the browser, so until a self-signed certificate is accepted by the user, the browser locks down all requests, including those for a status code. The browser could (if coded to) send back it's own status code for an insecure response, but that doesn't really help anything, and even then, you'd have issues with browser compatibility (chrome/firefox/IE having different standards... once again)
Since your original question was for checking the status of your server between being up versus having an unaccepted certificate, could you not make a standard HTTP request like so?
isUp = false;
isAccepted = false;
var isUpRequest = new XMLHttpRequest();
isUpRequest.open('GET', "http://localhost/custom/server/", true); //note non-ssl port
isUpRequest.onload = function() {
isUp = true;
var isAcceptedRequest = new XMLHttpRequest();
isAcceptedRequest.open('GET', "https://localhost/custom/server/", true); //note ssl port
isAcceptedRequest.onload = function() {
console.log("Server is up and certificate accepted");
isAccepted = true;
}
isAcceptedRequest.onerror = function() {
console.log("Server is up and certificate is not accepted");
}
isAcceptedRequest.send();
};
isUpRequest.onerror = function() {
console.log("Server is down");
};
isUpRequest.send();
Granted this does require an extra request to verify server connectivity, but it should get the job done by process of elimination. Still feels hacky though, and I'm not a big fan of the doubled request.