Redirecting the browser once identified

The Window object and how to change the location

<script type="text/javascript">
<!--
if (isIE3) {window.location.href="IE3_PAGE";}
else if (isNS3==1) {window.location.href="NETSCAPE3_PAGE";}
else if (isNS4) {window.location.href="NETSCAPE4_PAGE";}
else if (isIE4==1 || isIE5==1 || isNew==1)
{window.location.href="NEWEST_PAGE";}
//   -->
</script>

Remember to substitute IE3_PAGE, NETSCAPE3_PAGE etc for the URL of the correct page on your site.

Window is a global object in all browsers (can be addressed from any Javascript) and the location property contains the href just the same as a link (<a href=) contains a href property. Changing window.location.href using Javascript causes the browser to move to the new location.

The rest of the code is not executed once the location has been changed. So each browser leaves the code at a different point, IE3 first, NS3 second, etc.



This is part of www.codehelp.co.uk Copyright © 1998-2004 Neil Williams
See the file about.html for copying conditions.