Tilføjelser i Browser-Check.js
Hej Eksperter,Jeg har et script som jeg bruger til at definere hvilket stylesheet som skal inkluderes ud fra brugerens Browser type.
1) Jeg vil gerne have tilføjet Google Chrome!
2) Jeg vil gerne have tilføjet en default css i tilfælde af at browseren ikke er listet i scriptet.
Håber I kan hjælpe?
============================================================
Browser-Check.js
*****************
var BrowserDetect = {
init: function () {
this.browser = this.searchString(this.dataBrowser) || "An unknown browser";
this.version = this.searchVersion(navigator.userAgent)
|| this.searchVersion(navigator.appVersion)
|| "an unknown version";
this.OS = this.searchString(this.dataOS) || "an unknown OS";
},
searchString: function (data) {
for (var i=0;i<data.length;i++) {
var dataString = data[i].string;
var dataProp = data[i].prop;
this.versionSearchString = data[i].versionSearch || data[i].identity;
if (dataString) {
if (dataString.indexOf(data[i].subString) != -1)
return data[i].identity;
}
else if (dataProp)
return data[i].identity;
}
},
searchVersion: function (dataString) {
var index = dataString.indexOf(this.versionSearchString);
if (index == -1) return;
return parseFloat(dataString.substring(index+this.versionSearchString.length+1));
},
dataBrowser: [
{
string: navigator.userAgent,
subString: "Firefox",
identity: "Firefox"
},
{
string: navigator.userAgent,
subString: "MSIE",
identity: "Explorer",
versionSearch: "MSIE"
},
{
string: navigator.vendor,
subString: "Apple",
identity: "Safari"
},
],
dataOS : [
{
string: navigator.platform,
subString: "Win",
identity: "Windows"
},
{
string: navigator.platform,
subString: "Mac",
identity: "Mac"
},
{
string: navigator.platform,
subString: "Linux",
identity: "Linux"
}
]
};
function SetBrowserStylesheet(){
if (BrowserDetect.browser == 'Firefox') {
document.write('<link rel="stylesheet" type="text/css" href="/css/rg_firefox.css" />')
}
if (BrowserDetect.browser == 'Explorer' && BrowserDetect.version == '6') {
document.write('<link rel="stylesheet" type="text/css" href="/css/rg_ie6.css" />')
}
if (BrowserDetect.browser == 'Explorer' && BrowserDetect.version == '7') {
document.write('<link rel="stylesheet" type="text/css" href="/css/rg_ie7.css" />')
}
if (BrowserDetect.browser == 'Safari') {
document.write('<link rel="stylesheet" type="text/css" href="/css/rg_safari.css" />')
}
}