View Full Version : browser and OS detection

08-11-2005, 12:11 AM
I want to add a link to a map from a web page, my preferred map site is google map but have found that if the user is running IE on win98 their computer hangs. So I need a way of detecting if this instance occurs so that I can point them at multimap instead. I have tried writing the following script but can’t get it to work...

<script type="text/javascript" language="JavaScript">
if ((navigator.appName>="Internet Explorer")&&(userAgent.indexOf("windows 98"))
document.write("<a href='http://www.multimap.com/ '>see map<\/a>")
document.write("<a href='http://maps.google.co.uk/ '>see map<\/a>")

Can anyone tell me where I am going wrong?

08-11-2005, 02:51 PM
Noticed a couple of errors in your code:


if ((navigator.appName>="Internet Explorer")&&(userAgent.indexOf("windows 98"))


if((navigator.appName.indexOf("Internet Explorer") != -1) && (navigator.userAgent.indexOf("windows 98") != -1))

That should do it

08-11-2005, 09:57 PM
Thanks JUD.

I have been playing around with the code further, and with the help of the “Ranting Hippy” have come up with the following...

<script type="text/javascript" language="JavaScript">
if ( (navigator.appVersion.indexOf("MSIE") > 0) &&
(navigator.userAgent.indexOf("Windows 98") > 0) ) {
document.write("<a href='http://www.multimap.com/’> see map <\/a>");
} else {
document.write("<a href='http://maps.google.co.uk/ '>see map<\/a>");

Which is a variation on JUD's suggestion (but was done before I saw JUD's suggestion) I have tested this code and it works (so far). Feel free to use it if you have a similar problem.