JS-detection of browser version number
Frank
Status: New User - Welcome
Joined: 23 May 2006
Posts: 2
Reply Quote
Hello,

I have a very nice javascript that warns visitors if they have unchecked browsers or OSs. It looks like this:

:: Code ::
<script language="JavaScript" type="text/javascript">
<!--
function InformUser()
   {   
   if ((navigator.platform.indexOf("Win")!=-1) && ((navigator.userAgent.indexOf("MSIE 6")!=-1) || (navigator.userAgent.indexOf("Firefox/1.5")!=-1)))
   {
   return;
   }
   else
   {
   alert ('Welcome. \n\nThis web site has been checked with Internet Explorer 6 and Firefox 1.5, both on Windows.');
   }
   }
   InformUser();
//-->
</script>


The problem is that if a future visitor has for example Firefox 1.6 or later, he will also get the alert. So, what would the script have to look like for it to check for minimum versions?

Leaving versions out, which is technically possible, is not an option, because an important Firefox bug was only solved in version 1.5. That was the bug that most fold-out menus would not fold out over I-frames, or would fold out but not fold back again on mouseout.

Furthermore, the PHP detection script offers a perfect possibility, but a few very large web hosts here (that offer free web space with a mail account) do not have PHP running.

Thank you very much in advance for your effort!

R.,
Frank Conijn
Amsterdam
The Netherlands
Back to top
jeffd
Status: Assistant
Joined: 04 Oct 2003
Posts: 594
Reply Quote
Hi Frank, thanks for checking out the options first.

Using our javascript browser detection script, you can easily test for the exact firefox rv version, which is what you actually want to test for.

Various Gecko based browsers use different version numbers, but almost all of them use the same rv numbers.

On that page, you can see the script in action by ckicking the 'javascript browser test' link in the upper right option box.

As you can see, it correctly pulls out the rv number for use with > or < comparison operators, that's the 'nu' variable in the javascript detection script.

So you'd just change your detection to use this library, then compare like this:

:: Code ::
<script type="text/javascript">
if ( moz && nu >= 1.8 )
{
  // execute true condition
}
else
{
  // execute false condition
}
</script>

and that's about it.

Keep in mind that many browsers use the rv engine, gecko, Netscape, Mozilla, Seamonkey, Galeon, Epiphany, and some others, but of course, Firefox is by far the most popular among these, though you will also see mozillas and netscapes more often than you'd think.

If all you need to do is test for gecko version, you can cut a bunch of the javascript off to lighten the load on each page view, but it doesn't matter that much.
Back to top
Frank
Status: New User - Welcome
Joined: 23 May 2006
Posts: 2
Reply Quote
Thanks, Jeff!

I didn't know it was that simple.

I (only) check for Win+IE>=6 and Win+FF>=1.5, because I only check my websites with those combinations. As soon as I have the trimmed version well-tested, I'll let you know -- it seems to me that most webmasters do the same limited checking.

Just one more question for now: does the same browser act the same on Windows 98/2000/XP on the one hand, and on NT on the other? Just an educated guess will do, if you can't tell for sure.

R.,
Frank
Back to top
jeffd
Status: Assistant
Joined: 04 Oct 2003
Posts: 594
Reply Quote
Windows version shouldn't matter, but you should check for KHTML compliance as well, I can't remember how it handles the drop menu over iframe [or flash, by the way] issue. Firefox is fairly platform independent in terms of rendering, how something works in windows, linux, or mac will be about the same. The same cannot be said for the Microsoft Internet Explorer 5.x series that were made for the macs, but which are thankfully now becoming obsolete.

But just to be clear, you will see more Mac users, with Safari, by far, than NT 4 users on firefox, you'll probably even see more firefox/linux users than NT 4 users. So that's what I would worry about in terms of testing and functionality.

KHTML is what runs Safari and Konqueror, it's easy to check that by downloading a KDE based Linux livecd like kanotix, which will come with the latest konqueror, which uses roughly the same rendering engine as Safari, KHTML in both cases.

Burn the iso to a cd, boot into the cd, with a network connection available, and you can browse the web in konqueror in livecd mode without installing linux on your box, great tool for Safari compatibility testing, easy to do, and Safari has to be supported, that's a decent percentage of the market.

Also no reason not to test in Opera, 8.5 is latest stable release.

That's not a bug by the way, it's just how the browsers treat placing an item over another window, which is what an iframe, or a flash object, is technically speaking.

You should also check your menus when they go over flash, since it's exactly the same problem.
Back to top
Display posts from previous:   

All times are GMT - 8 Hours