Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q1102 Is there a way with the "onError" event to automatically link to a mirror site when the server hosting the main site fails?

You are here: irt.org | FAQ | JavaScript | Event | Q1102 [ previous next ]

Obviously not on a page in either site since how would the user get the page in the first place? Perhaps from the cache?

On a third site you could use an image and use it's onError event handler:

<html>
<head>
<title>Some Site other than Main or mirror Site</title>
<meta http-equiv="pragma" content="no-cache">
</head>

<body>
<img src="http.//www.mainsite.com/images/logo.gif" onError="location='http.//www.mirror.com/'">
</body>

</html>

On the main site the user would have loaded the page from cache but then the image must not be cached:

<html>
<head>
<title>Main Site - page must come from cache</title>

<script language="JavaScript"><!--
function testSite() {
   if (!document.images) return;
   today = new Date();
   document.images["logo"].src = 'http.//www.mainsite.com/images/logo.gif?'+today.getTime();
}
//--></script>

</head>

<body onLoad="testSite()">
<img name="logo" src="http.//www.mainsite.com/images/logo.gif" onError="location.href='http.//www.mirror.com/'">
</body>

</html>

©2018 Martin Webb