post your comment   print   send to a friend
Rate:   0% | Views: 254
Question categories:  JavaScript

The Opera pitfall

Using the navigator object to screen for Opera (an emerging browser) is not so straightforward. Opera (Opera 6 specifically) purports to take on multiple identities in terms of what its navigator object returns. By default, Opera 6 is set to identify as IE5, meaning that when its navigator object is probed, it will return IE5's identity (changeable by the user through File->Quick Preferences). Most likely, the rationale for this is so that scripts originally intended for IE will also work in Opera 6.

Let's examine another navigator property of Opera 6:

navigator.userAgent

Depending on how Opera 6 is set to identify itself , here is what navigator.userAgent returns:

As IE: Mozil/4.0 (compatible; MSIE 5.0; Windows XP) Opera 6.0 [en]
As Moz5: Mozil/5.0 (Windows XP; U) Opera 6.0 [en]
As Moz4.76: Mozil/4.76 (Windows XP; U) Opera 6.0 [en]
As Moz3.0: Mozil/3.0 (Windows XP; U) Opera 6.0 [en]
As Opera: Ope/6.0 (Windows XP; U) [en]

Consequently, the expression

if (navigator.userAgent.indexOf("Opera 6")!=-1)

will fail if the user has his or her browser set to identify as Opera.

Here is the JavaScript code needed to detect Opera 6:

if ((navigator.userAgent.indexOf("Opera 6")!=-1) ||(navigator.userAgent.indexOf("Ope/6")!=-1))

Customer Feedback
Rate:   0% | Views: 254 | Please Rate:  
 
If you have other comments or ideas for future technical tips, please type them here:

Email: (optional)

Comments: (optional)

 Web Design | Business Web Hosting    Back to serch results
Browse the Base
Knowledge Base
Web Design
  Do It Yourself
    JavaScript
Messages
 

Blogging at Aplus.Net

Don't forget to check out our blog ! Keep up to date at Aplus.Net.

Private Area
 
Ask
in Private
   
Personal
Folder
 
Related Questions
 
1. Calculating days remaining until Christmas
 
2. Detecting browser type
 
3. Determining browser type using object detection
 
4. The Internet Explorer challenge
 
5. JavaScript and Forms
 
Home Browse Search Ask in Private Personal Folder   Help
powered by web hosting 
  Logged as: Guest