Main Page

Detecting Konqueror/Safari

isMinOpera4 = fOperaVersion >= 4;
isMinOpera5 = fOperaVersion >= 5;
isMinOpera6 = fOperaVersion >= 6;
isMinOpera7 = fOperaVersion >= 7;
isMinOpera7_5 = fOperaVersion >= 7.5;
This completes the first section of the browser detection code. With just this section, it is possible to
determine if a browser is Opera; and if it is, which version. Next up is the other
browser: Safari.
Detecting Konqueror/Safari
Both Konqueror and Safari are based on the KHTML project and so can be considered the same. The
problem is that you have no way to tell what version of KHTML the browser is using. Therefore, you can
detect whether KHTML is in use, but you still need to rely on the browser version numbers to indicate
browser capabilities.
To start, take a look at a few KHTML-based user agent strings:
Mozilla/5.0 (compatible; Konqueror/2.2.2; SunOS)
Mozilla/5.0 (compatible; Konqueror/3; Linux; de, en_US, de_DE)
Mozilla/5.0 (compatible; Konqueror/3.1; Linux 2.4.20)
Mozilla/5.0 (compatible; Konqueror/3.2; FreeBSD) (KHTML, like Gecko)
Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/51 (like Gecko) Safari/51
Mozilla/5.0 (Macintosh; U; PPC Mac OS X; es-es) AppleWebKit/106.2 (KHTML, like
Gecko) Safari/100.1
Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/124 (KHTML, like Gecko)
The first four strings are from Konqueror; the last two are from Safari. Notice a few things in this mix-
ture. First, not all the user-agent strings contain the string
, so it is necessary to search for
as well as
. Apple suggests that you look for
instead of
because other developers may embed the Apple Web Kit to create
other browsers. Second, the Konqueror version number has no relation to either the Apple Web Kit or
Safari version numbers.
So to start, you should determine if the browser is KHTML based:
var isKHTML = sUserAgent.indexOf(“KHTML”) > -1
|| sUserAgent.indexOf(“Konqueror”) > -1
|| sUserAgent.indexOf(“AppleWebKit”) > -1;
is set, you can then determine which KHTML browser is being used.
if (isKHTML) {
isSafari = sUserAgent.indexOf(“AppleWebKit”) > -1;
isKonq = sUserAgent.indexOf(“Konqueror”) > -1;
Browser and Operating System Detection
11_579088 ch08.qxd 3/28/05 11:38 AM Page 239

JavaScript EditorFree JavaScript Editor     Ajax Editor