Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Opera browser identification

Status
Not open for further replies.

starway

Programmer
Jan 15, 2002
1,010
UA
Opera browser is known for it's ability to "spoof" browser name detection. For example, user of the latest official Opera 6.0 release has several default options of it's browser identification, such as Mozilla, IE and Opera itself.

There are several ways to detect the real values, one of them is checking the value of [tt]navigator.userAgent[/tt]. Here what I got using Opera 6.0 on Win2k system:

Id as Mozilla 5.0: Mozilla/5.0 (Windows 2000; U) Opera 6.0 [en]

Id as Opera: Opera/6.0 (Windows 2000; U) [en]

Id as MSIE 5.0: Mozilla/4.0 (compatible; MSIE 5.0; Windows 2000) Opera 6.0 [en]

You may see that each string contains "Opera" substring, that tells you exactly what browser are you dealing with. Also, there's an option to see what type is Opera "pretending" to be at this moment. [tt]navigator.appName[/tt] is good enough for this. We can perform some check-ups like these:

if ( navigator.userAgent.indexOf("Opera") !=-1 ) // this is Opera

if (( navigator.userAgent.indexOf("Opera") !=-1 ) && ( navigator.userAgent.indexOf("MSIE") !=-1)) //this is Opera identified as IE

if (( navigator.userAgent.indexOf("Opera") !=-1 ) && ( navigator.appName == "Opera" )) // pure Opera!

The results will give us the full picture. There's also another way to find out whether it is Opera or not. Check the folowing:

window.opera

The use of this property of window object in Opera browser let us know what we deal with:
var opera = (window.opera ? true : false)

This is a brief (but most important part) of my FAQ submitted today.
Read more here: faq216-1512
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top