Welcome to WebmasterWorld Guest from 54.198.77.172

Forum Moderators: open

Message Too Old, No Replies

Javascript: Identifying visitor's OS and Browser

Best way?

     
4:54 pm on Jun 12, 2003 (gmt 0)

New User

10+ Year Member

joined:June 11, 2003
posts:10
votes: 0


I've seen a bunch of scripts for this on the web, but each is slightly different... has anyone found an optimized script to ID your visitor's OS and browser?

Also, what is the best way to collect this info?

Thanks.

8:54 pm on June 12, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member drdoc is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 15, 2002
posts:6807
votes: 0


DevEdge [developer.netscape.com] has a very good script.

However, there is no such thing as an "optimized" script for your needs. Do you need to recognize all browsers? Well, then it's important that many common browsers can identify themselves as any browser.

Browser sniffing is seldom very reliable. If possible, try to avoid it.

Now, the best advice I can give you is to download DevEdge's user agent sniffer. Then you need to modify it to suit your needs. Learn how to use simple JavaScript constructs as:

navigator.userAgent
navigator.appName

10:05 pm on June 12, 2003 (gmt 0)

New User

10+ Year Member

joined:June 12, 2003
posts:7
votes: 0


I pretty much agree with the post above 'DevEdge' but in addition to that info, try to do your script in a process that gets the best results. What I mean is identify the OS first with a java script, then 'if' WIN OS run a VB if not run another java script. In most cases a WIN OS is easier to sniff than Linux etc. What I have found in general is that people who surf with browsers that run on Linux OS almost always don't want their browser to be sniffed, you have to build a round-a-bout method to sniff the browser at site's entrance. Once you sniff the OS the rest is fairly straightforward. Well! if you want to get real technical and want to accommodate wireless devices and such you will need to work harder to create a sniffer.
5:34 am on June 13, 2003 (gmt 0)

New User

10+ Year Member

joined:June 11, 2003
posts:10
votes: 0


Thanks for the help. By the way, speaking of JS, it's compatible with HTML 4.0 strict, right? I'm getting an error in my w3c validation at

'<script language="JavaScript" type="text/JavaScript">'

with the validator saying 'language' isn't valid

7:32 am on June 13, 2003 (gmt 0)

Moderator from US 

WebmasterWorld Administrator keyplyr is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Sept 26, 2001
posts:6171
votes: 77


Use <script type="text/javascript" src="your_script.js">

1:48 pm on June 13, 2003 (gmt 0)

New User

10+ Year Member

joined:June 11, 2003
posts:10
votes: 0


Stupid question perhaps, but since I'm new to JS... I assume I drop the src= part if my script is embedded in the head of my markup?
1:56 pm on June 13, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member korkus2000 is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 20, 2002
posts:3732
votes: 0


Yes. Source is only needed to call an external .js file.