...

View Full Version : browser and OS detection



dimkim
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>")
else
document.write("<a href='http://maps.google.co.uk/ '>see map<\/a>")
-->
</script>

Can anyone tell me where I am going wrong?

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

Replace


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

with


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

That should do it

dimkim
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>");
}
-->
</script>

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.

Kim



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum