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))