Too often, what seems easy to use can be quite complex. In this case, JavaScript prohibits cross-domain calls for security measures, so XMLHttpRequest is not an option.
It seems your best option is to implement the solution discussed here: Check for URL availability using javascript .
I quickly tested in Chrome and IE, and this code worked well in both. (IE really complained about running the script on the local page, but that would be the same regardless of the solution.)
<html> <head></head> <body> <script> function checkServerStatus(url) { var script = document.body.appendChild(document.createElement("script")); script.onload = function() { alert( url + " is online."); }; script.onerror = function() { alert( url + " is offline."); window.location.replace("http://google.com"); }; script.src = url; } checkServerStatus("http://google.com"); checkServerStatus("http://intranet"); </script> </body>
Here is another link that discusses this solution: https://petermolnar.eu/test-site-javascript/ .
Hope this helps.
source share