Home Articles FAQs XREF Games Software Instant Books BBS About FOLDOC RFCs Feedback Sitemap
irt.Org
#

Q239 How can I check if the browser is Opera and which version?

You are here: irt.org | FAQ | JavaScript | Misc | Q239 [ previous next ]

The developers of Opera made to decision to fake the Netscape browser so as to enable image swapping to occur. IMHO this was a bad move, as correctly written scripts do not check for the browser but for the image object.

Anyway the following script:

<SCRIPT LANGUAGE="JavaScript"><!--
document.write('<P>navigator.appCodeName = ' + navigator.appCodeName);
document.write('<P>navigator.appName = ' + navigator.appName);
document.write('<P>navigator.appVersion = ' + navigator.appVersion);
document.write('<P>navigator.userAgent = ' + navigator.userAgent);
//--></SCRIPT>

returns on Opera 3.1:

navigator.appCodeName = Mozilla
navigator.appName = Netscape
navigator.appVersion = 3.0
navigator.userAgent = Mozilla/3.0 (compatible; Opera/3.0; Windows 95/NT4) v3.1

Therefore to check if the browser really is Opera and not Netscape try:

<SCRIPT LANGUAGE="JavaScript"><!--
if (navigator.userAgent.indexOf('Opera') > -1) {
    version = navigator.userAgent.substring(navigator.userAgent.indexOf('v'));
    alert('You are using Opera version ' + version);
}
//--></SCRIPT>

©2018 Martin Webb