HTML redirect to different URLs based on server availability

The main page for the workstations of our company is http: // intranet , which is our internal SharePoint site established by group policy. Right now, if a user tries to open IE on a laptop when he is off-site, they are (obviously) welcomed with a "Page not showing" error. This causes confusion among our less sophisticated users, and they end up calling our help desk, although there is nothing wrong with connecting to the Internet.

What I would like to do is set the default homepage to a local .html file that will use HTTP redirection to forward the browser to our public website if the internal URL is not available.

Is it possible?

+5
source share
1 answer

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.

+3
source

Source: https://habr.com/ru/post/1239826/


All Articles