I wish my Users to be seamlessly sent to an alternate URL using a redirect if the original URL is not available or times out.

As a total newbie to JS & AJAX, I wonder if a solution is possible to detect failure to connect to URL_a and automatically redirect to URL_b?

Any guidance will be very much appreciated.

I know 2 reliable ways to redirect visitors:

<script type="text/javascript">
window.location.href="http://example.com/redirect.html";
</script>

or you can redirect them using an .htacces file:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(mypage.html)$ http://www.example.com/redirect.html [NC]

So if someone visits www.example.com/mypage.html, he will be redirected to http://www.example.com/redirect.html

~G

Hi Graphix,

Many thanks for taking the time to reply. Unfortunately a simple redirect won't solve the problem.

Imagine this - an HTML file on a User's PC will be called and;

- it will immediately redirect to URL-A

- if URL-A loads - terrific!

However

- if URL-A fails to load, then switch to URL-B

This is to detect _server failure_ because when such happens there will be no 404 messages, just nothing.

Cheers.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.