Redirect browser only if website is available

I have an HTML file stored on the local file system. I need it to redirect (or otherwise display in some way) the remote website ONLY if the site is accessible and accessible. If the site is unavailable, I need to display a user-friendly message.

I currently have:

<html>
<body onload="window.location.href='http://someserver/';">
    <p>Connecting to remote server...</p>
</body>
</html>

The problem is that if the server is unavailable, the user is presented with the ugly page "cannot find server" from a web browser. I would prefer to display some custom HTML indicating the situation to the user if page navigation has occurred. What are some commonly used solutions that I should try, will this work well for this?

Requirement: It must work in IE6 through IE9. FireFox / WebKit engines will not be used for this application.

+3
source share
2 answers

An easy way would be to attempt to download a known small image, and you will find that the download is completed or not.

<img src="http://www.rgagnon.com/images/pdf.gif"
   onload="window.location='http://www.rgagnon.com';"
   onerror="window.location='http://www.google.com';"
>

If the pdf.gif file is uploaded, we go to the site if we donโ€™t go somewhere else.

+7
source

You can use an AJAX style request at boot time to ensure that the server is alive before redirecting the browser to it, but there is no guarantee that the server will still be alive when the redirection occurs.

+2
source

All Articles