Introduction to JavaScript Tutorial
By Neil Williams2007-11-09
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.
Tutorial Pages:
» It's flavours and versions
» Structure and syntax
» Data types and objects
» Functions and operators
» JavaScript Statements A-F
» JavaScript Statements G-Z
» JavaScript Events
» JavaScript Global Properties
» Javascript code to identify your browser
» Redirecting the browser once identified
Copyright © Neil Williams
