Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

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

irt.org | Knowledge Base | JavaScript | Event | Q1102 [ previous next ]

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

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>

Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.