Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

Coding Forum


You are currently viewing our Coding Forum as a guest. Please register to participate.
Login



Reply
Old 06-16-2002, 02:31 PM Browser detection
Junior Talker

Posts: 4
Location: texas
Trades: 0
What is the industry standard (if such a thing exists) for browser detection using Javascript? I used to look for magic strings in the user-agent header ("MSIE", etc) but lately I have been using object-based detection (document.all, document.layers, ...). But, since Netscape 6 doesn't support the layers object, I have had to resort to a generic }else{ for that browser. It just seems that there has to be a better way to do this. Have any of you found a better way to handle this?
-MrgnWlkr
MrgnWlkr is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-16-2002, 02:58 PM
Tiggy's Avatar
Ultra Talker

Posts: 249
Location: Lancashire, UK
Trades: 0
I do all my browser detection on the server side, but then I'm not using code that is likely to break... I only do it to accomodate the changes in the CSS. I tend to look for strings...

1st, I look for "Opera" - this saves you picking it up as MSIE or Netscape if it is set to emulate a browser.
2nd, I look for "MSIE" - picks up MSIE browsers.
3rd, I look for "Netscape6" (or was it with a space) - picks out Netscape 6 over earlier versions...
Anything left I use a default style sheet for, if it can understand it that is.

Of course, I could go picking out others, but these are the main three I see so I don't usually bother doing too much. My needs are simple however, I don't need to test for DOM support...
__________________
Web Site Owner's Resource -
Please login or register to view this content. Registration is FREE
Tiggy is offline
Reply With Quote
View Public Profile
 
Old 07-12-2002, 12:33 AM
Junior Talker

Posts: 4
Trades: 0
If there is a standard, I would say it's using the navigator object in JavaScript. However, many coders resort to object detection instead, which is sufficient if the detection is to refine your script so it runs in supported browsers only. For example, in an image slideshow script, the code:

if (document.images)

would be used to detect support for the images object.

Regarding browser detection using the navigator object, I wrote a rather comprehensive tutorial on the subject a while ago: http://www.javascriptkit.com/javatutors/navigator.shtml
__________________
-
Please login or register to view this content. Registration is FREE
- JavaScript tutorials and 400+ scripts!
-
Please login or register to view this content. Registration is FREE
- Web coding and development forums
georgec is offline
Reply With Quote
View Public Profile
 
Old 07-19-2002, 07:47 AM
DaveTodd's Avatar
Evil Psycho Alien

Posts: 684
Location: Sheffield, England
Trades: 0
javascript is too buggy for browser detection. lots of people have it turned off, thus losing you hits, and potential customers. i use php, never failed me yet. php is good because its server side, so the client cannot turn it on and off, therefore it works 100% of the time. i've included a really good script here for browser redirection, it use it myself on this site, and its worked perfectly so far.
be sure to include a noscript section, and optomise the page for search engines, because even though your client will not see the page, spiders will.
i use php because it is fast, efficient, and importantly, click free. there is no redirection click sound, it all happens so fast, the page doesn't even load, the check just goes straight through, the user has no idea they have been redirected
Attached Files
File Type: txt index.txt (1.5 KB, 80 views)
__________________
take care,
Dave ;)

Please login or register to view this content. Registration is FREE
DaveTodd is offline
Reply With Quote
View Public Profile
 
Old 07-22-2002, 12:23 AM
dk01's Avatar
Ultra Talker

Posts: 373
Location: Ames, IA
Trades: 0
The problem with this is is browsers such as Opera are spoofing as something else it still sends the spoofed version in the http header. This is why javascript methods work better for me than server-side methods because scripts like this one can detect Opera no matter what it is spoofing as. For more insight you may want to look here.
Glad to be here!
-dk
__________________
Did I help you? If so, be nice and throw me some
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
dk01 is offline
Reply With Quote
View Public Profile
 
Old 07-22-2002, 07:59 AM
Novice Talker

Posts: 6
Trades: 0
It just depends on how critical the task at hand is... if you're redirecting to a critical page based on the browser type then you should do it on the server. If it's just basic DHTML and what not then do it on the client.
__________________

Please login or register to view this content. Registration is FREE
: Get the best viral marketing tool on the planet and watch your visitor count skyrocket!
SiteTell.com is offline
Reply With Quote
View Public Profile
 
Old 07-23-2002, 01:59 PM
Tiggy's Avatar
Ultra Talker

Posts: 249
Location: Lancashire, UK
Trades: 0
Quote:
Originally posted by dk01
The problem with this is is browsers such as Opera are spoofing as something else it still sends the spoofed version in the http header.
In my experience Opera always identifies itself as Opera even when it is Spoofing - the spoof just takes advantage of the poorly written browser detection scripts that are still going around.

Examples of some spoofed Opera files in my logs - I can confirm they were recognised as Opera by my technique above as they were correctly served the Opera style sheet.

Opera attempting to spoof
Mozilla/4.0 (compatible; MSIE 5.0; Windows 2000) Opera 6.04 [en] - Opera 6.04 spoofing MSIE 5 on a Win 2K machine
Mozilla/4.0 (compatible; MSIE 5.0; Windows NT 4.0) Opera 6.02 [en] - Opera 6.02 spoofing MSIE 5 on a Win NT machine
Mozilla/4.0 (compatible; MSIE 5.0; Linux 2.4.18-6mdk i686) Opera 6.0 [en] - Opera 6.0 spoofing MSIE 5 on a Linux machine!
Mozilla/4.71 (Windows 3.10;US) Opera 3.62 [en] - Opera 3.62 spoofing Netscape 4.71 on a Win 3.1 machine

Opera as itself
Opera/6.02 (Linux 2.4.18 i686; U) [en] - Opera 6.02 on a Linux machine
Opera/4.0 (Windows 95;US) [en] - Opera 4 on a Win 95 machine
Opera/5.12 (Windows 98; U) [en] - Opera 5.12 on a Win 98 machine
Opera/6.02 (Windows XP; U) [en] - Opera 6.02 on a Win XP machine (I've just noticed that Opera is the only browser to visit my site to identify Win XP as XP in the UA string - strange)

IIRC - I remember reading somewhere that Opera doesn't engage in true spoofing for the sake that it would never get true representation in the logs. This makes sense and appears to be the case - I'm sure the folks at Opera would like to prove they have so much market share by making sure their name is in all the requests their browser makes, regardless if it is spoofing or not.

In conclusion then, when Opera is spoofing it just moves the Opera identification to the end... so any decent browser sniffer is going to correctly identify it regardless of how the user wants to identify it.
__________________
Web Site Owner's Resource -
Please login or register to view this content. Registration is FREE
Tiggy is offline
Reply With Quote
View Public Profile
 
Old 07-30-2002, 08:02 AM
DaveTodd's Avatar
Evil Psycho Alien

Posts: 684
Location: Sheffield, England
Trades: 0
if opera is spoofing, then it shouldn't matter. if it is spoofing as IE5, and gets picked up as IE5, then the php will redirect it to the IE page, thus it will display correctly if it is spoofing? i'm presuming this as i have never used opera.

tried netscape for the first time properly the other day, there was a mistake, never agein. give me the simplicity of IE, looks old, works fine, that'll do me

ps, i'm back from holiday
__________________
take care,
Dave ;)

Please login or register to view this content. Registration is FREE
DaveTodd is offline
Reply With Quote
View Public Profile
 
Old 07-31-2002, 06:28 PM
Tiggy's Avatar
Ultra Talker

Posts: 249
Location: Lancashire, UK
Trades: 0
Opera is spoofing in the right way for statistical analysis (that is, Opera is picked up as Opera by log analysis tools) - although if it spoofs its way past the scripts no depends on the browser sniffer... if they look for Opera first then IE, then it should easily pick it up, check for Opera too late and it gets mistaken for the spoof...
__________________
Web Site Owner's Resource -
Please login or register to view this content. Registration is FREE
Tiggy is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Browser detection
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.35188 seconds with 13 queries