↑
Main Page
Konqueror
Next, set up the variables for the different versions of the browsers:
var isMinSafari1 = isMinSafari1_2 = false;
var isMinKonq2_2 = isMinKonq3 = isMinKonq3_1 = isMinKonq3_2 = false;
To determine the version of Safari, you can either interpret the build number or the Apple Web Kit ver-
sion. As mentioned previously, Apple suggests you only use the Apple Web Kit information. Safari 1.0
uses Apple Web Kit version 85 whereas Safari 1.2 uses version 124. To extract this information, it is again
necessary to use a regular expression.
Looking at the user-agent strings at the beginning of this section, you see that the Apple Web Kit version
can have decimals, but doesn’t always. This makes the regular expression a little bit more complicated
than others in this chapter:
var reAppleWebKit = new RegExp(“AppleWebKit\\/(\\d+(?:\\.\\d*)?)”);
This expression uses a non-capturing group to include the decimal point and numbers after it. Other
than that bit of trickery, the capturing group returns the version:
if (isKHTML) {
isSafari = sUserAgent.indexOf(“AppleWebKit”) > -1;
isKonq = sUserAgent.indexOf(“Konqueror”) > -1;
if (isSafari) {
var reAppleWebKit = new RegExp(“AppleWebKit\\/(\\d+(?:\\.\\d*)?)”);
reAppleWebKit.test(sUserAgent);
var fAppleWebKitVersion = parseFloat(RegExp[“$1”]);
isMinSafari1 = fAppleWebKitVersion >= 85;
isMinSafari1_2 = fAppleWebKitVersion >= 124;
}
}
To determine the version of Konqueror, the regular expression is also a little bit complicated because
Konqueror uses version numbers with zero, one, or two decimal points. Because of this, multiple non-
capturing groups are necessary to capture all the variations.
var reKonq = new RegExp(“Konqueror\\/(\\d+(?:\\.\\d+(?:\\.\\d)?)?)”);
This regular expression says to match the string
“Konqueror”
, followed by a forward slash, followed by
at least one digit, which may or may not be followed by a decimal point and one or more digits, which
may or may not be followed by another decimal point and one or more digits.
After this value is extracted, it must be tested using the
compareVersions()
function in order to deter-
mine the minimal browser versions:
if (isKHTML) {
isSafari = sUserAgent.indexOf(“AppleWebKit”) > -1;
isKonq = sUserAgent.indexOf(“Konqueror”) > -1;
if (isSafari) {
240
Chapter 8
11_579088 ch08.qxd 3/28/05 11:38 AM Page 240
Free JavaScript Editor
Ajax Editor
©
→