Javascript  -  Browser Version Detection & Redirection

As with any new technology, DHTML is not 100% available to all the people who come to view your web pages.  This can result in problems when someone with a non 4.0 - version browser looks at a page which was created with the “CSS and Layers” HTML Output setting...

To that end, here’s a JavaScript (readable by 3.0 browsers) procedure to (a) detect the version of the browser reading the page and (b) automatically direct the customer to the appropriate (CSS or non-CSS) page.

To see this Javascript in action, click here.

This script uses the navigator.appVersion property, specifically the first character of that property, which is always a version number.  Since we know that all browsers before 4.0 can have problems dealing with CSS pages, we know to route these viewers to a more 3.0-friendly page...

Insert the following code into the “Between Head Tags” field of the “Layout HTML” window:

<SCRIPT LANGUAGE=”JavaScript”>
<!-- Hide from non-JS Aware Browsers
function checkver()
{
  if(navigator.appVersion.substring(0,1) < 4)
  { window.location=”
URL”}
  else
  { window.location=”
URL2”}
}
// end hiding -->
</SCRIPT>



Where URL and URL2 are the URLs you want the browser to be redirected to. 

If you are using this just to direct pre-4.0 browsers away from the page, you can remove everything in italics since the code in italics routes the browser to a page only if the browser is of a version higher than 3.

And insert this code into the “Inside Body Tag” field:

onload = checkver()

And that should do it.

Go Back to Previous Page

Have a question that you can´t find the answer to? Want to report a possible bug?

Send a help request to NetObjects Technical Support