Menu
infologic > developer > Alternate Link

 

The alternate link javascript can be used in a web page to allow an alternative image/link to be shown where the first is not accessible.

On page load, the browser attempts to load the first image. If successful, this image is shown and clicking on the image will trigger a download of the web page at the first (preferred) URL. If the browser is unable to load the first image (site unavailable or image file not found), the second image is loaded instead. Clicking on this alternative image will trigger a download of the web page at the alternative URL.

Possible uses

Substituting a link cleanly by removing the image file.

Redirect to an alternative site if the primary site is unavailable, without making changes to the web server configuration.

Only include a link IF the image file is available (substitute a blank image).

Instructions for use

1. Copy the alternateLink.js javscript file into an appropriate directory, e.g. ../js

2. Include code to load the script, once in the html page.
E.g.

<script type="text/javascript" language="JavaScript" src="../js/alternateLink.js"></script>

3. Include one or more calls to islAlternateLink wherever two alternative image/links are required. Note careful use of single and double quotes.
E.g.

<script JavaScript>
<!--
islAlternateLink("",
"http://host.name.com/images/image1.gif",
'width="60" height="40" border="0" alt="Link to a site"',
"http://host.name.com/index.html",
'target="_self"',
"../images/image2.gif",
"#localTag");
// -->
</script>

This example would show image1.gif and link to host.name.com/index./html if image1.gif could be found. If not, the browser would show image2 and link to localTag in the current document.