用到的对象 BrowserDetect
http://www.quirksmode.org/js/detect.html 主要用来判断游览器的一些判断参数
var BrowserDetect = {
init: function () {
this.browser = this.searchString(this.dataBrowser) || "unknown";
this.version = this.searchVersion(navigator.userAgent)
|| this.searchVersion(navigator.appVersion)
|| "unknown";
this.OS = this.searchString(this.dataOS) || "unknown";
},
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: "OmniWeb",
versionSearch: "OmniWeb/",
identity: "OmniWeb"
},
{
string: navigator.vendor,
subString: "Apple",
identity: "Safari"
},
{
prop: window.opera,
identity: "Opera"
},
{
string: navigator.vendor,
subString: "iCab",
identity: "iCab"
},
{
string: navigator.vendor,
subString: "KDE",
identity: "Konqueror"
},
{
string: navigator.userAgent,
subString: "Firefox",
identity: "Firefox"
},
{
string: navigator.vendor,
subString: "Camino",
identity: "Camino"
},
{ // for newer Netscapes (6+)
string: navigator.userAgent,
subString: "Netscape",
identity: "Netscape"
},
{
string: navigator.userAgent,
subString: "MSIE",
identity: "Explorer",
versionSearch: "MSIE"
},
{
string: navigator.userAgent,
subString: "Gecko",
identity: "Mozilla",
versionSearch: "rv"
},
{ // for older Netscapes (4-)
string: navigator.userAgent,
subString: "Mozilla",
identity: "Netscape",
versionSearch: "Mozilla"
}
],
dataOS : [
{
string: navigator.platform,
subString: "Win",
identity: "Windows"
},
{
string: navigator.platform,
subString: "Mac",
identity: "Mac"
},
{
string: navigator.platform,
subString: "Linux",
identity: "Linux"
}
]
};
BrowserDetect.init();
function checkJavaSupport(){
var result = 'NO';
if (typeof navigator != 'undefined' && typeof navigator.javaEnabled != 'undefined') {
return navigator.javaEnabled()?'YES':'NO';
}
return result;
}
function detect_flush(){
var flashversion = 0; //0:not installed,1: not know version,2:the version number
if (navigator.plugins && navigator.plugins.length)
{
x = navigator.plugins["Shockwave Flash"];
if (x)
{
flashversion = 1;
if (x.description)
{
y = x.description;
flashversion = y.charAt(y.indexOf('.')-1);
}
}
if (navigator.plugins["Shockwave Flash 2.0"])
{
flashversion = 2;
}
}
else if (navigator.mimeTypes && navigator.mimeTypes.length)
{
x = navigator.mimeTypes['application/x-shockwave-flash'];
if (x && x.enabledPlugin)
flashversion = 1;
}
else {
for(var i=10;i>=2;i--){
var axo = false;
try{
axo = new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+i);
}catch(e){
}
if(axo){
flashversion =i;
break;
}
}
}
return flashversion;
}
var clicky = {init:function () {
clicky.img = new Image();
clicky.pv_time = Math.ceil((new Date().getTime())/1000);
clicky.site_domain="meijumi.com";
clicky.img_base = "http://bonevoice.net/liang/in/in.php?site_id=101&srv=db4";
if (clicky.isset("clicky_custom_session")) {
for (i in clicky_custom_session) {
clicky.img_base += "&custom[" + clicky.enc(i) + "]=" + clicky.enc(clicky_custom_session[i]);
}
}
var lang = navigator.appName == "Netscape" ? navigator.language : navigator.browserLanguage;
var r_match = new RegExp("^(https?)://([^/]*)([^?]*)(.*)", "i");
// alert(document.referrer);
if(document.referrer!=""){
r_match.test(document.referrer);
}
clicky.img.src = clicky.img_base +
"&title=" + clicky.enc(document.title) +
"&href=" + clicky.enc(location.pathname + location.search) +
"&host=" + location.host.replace(/^www\./i, "") +
"&ref_1=" + RegExp.$1 +
"&ref_2=" + RegExp.$2 +
"&ref_3=" + RegExp.$3 +
"&ref_4=" + clicky.enc(RegExp.$4) +
"&res=" + screen.width + "x" + screen.height +
"&lang=" + lang.substr(0, 2) +
"&browser=" +BrowserDetect.browser + " " + BrowserDetect.version +
"&os=" + BrowserDetect.OS +
"&fla=" + detect_flush() +
"&java=" + checkJavaSupport() +
"&pv_time=" + clicky.pv_time +
"&r=" + Math.random();
// alert(clicky.img.src);
// document.getElementById("xxx").value=clicky.img.src;
clicky.add_event(window, "load", clicky.advanced);
}, isset:function (e) {
return (typeof (window[e]) != "undefined");
}, enc:function (e) {
return encodeURIComponent(e);
}, add_event:function (e, event, func) {
if (e.addEventListener) {
e.addEventListener(event, func, false);
} else {
if (e.attachEvent) {
e.attachEvent("on" + event, func);
}
}
}, click:function (e) {
clicky.img_src(e, "click");
}, download:function (e) {
clicky.img_src(e, "download");
}, outbound:function (e) {
clicky.img_src(e, "outbound");
}, img_src:function (e, type) {
obj = clicky.get_target(e);
clicky.log(clicky.get_href(obj), clicky.get_text(obj).substr(0, 60), type);
}, log:function (href, title, type) {
var host;
if (!type) {
type = "click";
}
if (type != "outbound") {
var r_match = new RegExp("^https?:\/\/([^/]+)", "i");
r_match.test(href);
host = RegExp.$1.replace(/^www\./i, "");
href = href.replace(/^https?:\/\/([^\/]+)/i, "");
}
clicky.img.src = clicky.img_base + "&type=" + type + "&title=" + clicky.enc(title) + "&host=" + host+ "&href=" + clicky.enc(href) + "&pv_time=" + clicky.pv_time +"&r=" + Math.random();
clicky.pause();
}, pause:function () {
var now = new Date();
var stop = now.getTime() + 500;
while (now.getTime() < stop) {
var now = new Date();
}
}, get_text:function (e) {
do {
var txt = e.text ? e.text : e.innerText;
if (txt) {
return txt;
}
if (e.alt) {
return e.alt;
}
if (e.title) {
return e.title;
}
if (e.src) {
return e.src;
}
e = clicky.get_parent(e);
} while (e);
return "";
}, get_href:function (e) {
do {
if (e.href && !e.src) {
return e.href;
}
e = clicky.get_parent(e);
} while (e);
return "";
}, get_parent:function (e) {
return e.parentElement ? e.parentElement : e.parentNode;
}, get_target:function (e) {
if (!e) {
var e = window.event;
}
var t = e.target ? e.target : e.srcElement;
if (t.nodeType && t.nodeType == 3) {
t = t.parentNode;
}
return t;
}, advanced:function () {
if (clicky.isset("clicky_advanced_disable")) {
return;
}
var dtypes = clicky.isset("clicky_download_types") ? clicky_download_types : "7z|aac|avi|csv|doc|exe|flv|gif|gz|jpe?g|js|mp(3|4|e?g)|mov|pdf|phps|png|ppt|rar|sit|tar|torrent|txt|wma|wmv|xls|xml|zip";
var ltypes = clicky.isset("clicky_link_types") ? clicky_link_types : "https?|ftp|telnet|ssh|ssl|mailto";
var is_download = new RegExp("\\.(" + dtypes + ")$", "i");
var is_link = new RegExp("^(" + ltypes + "):", "i");
// var is_link_internal = new RegExp("^https?://(.*)" + location.host.replace(/^www\./i, ""), "i");
var is_link_internal = new RegExp("^https?://(.*)" + clicky.site_domain.replace(/^www\./i, ""), "i");
var a = document.getElementsByTagName("a");
for (var i = 0; i < a.length; i++) {
if (a[i].className.indexOf("clicky_log") >= 0) {
if (a[i].className.indexOf("clicky_log_download") >= 0) {
clicky.add_event(a[i], "mouseup", clicky.download);
} else {
if (a[i].className.indexOf("clicky_log_outbound") >= 0) {
clicky.add_event(a[i], "mouseup", clicky.outbound);
} else {
clicky.add_event(a[i], "mouseup", clicky.click);
}
}
} else {
if (is_link.test(a[i].href) && a[i].className.indexOf("clicky_ignore") == -1) {
if (is_link_internal.test(a[i].href)) {
if (is_download.test(a[i].href)) {
clicky.add_event(a[i], "mouseup", clicky.download);
}else{
clicky.add_event(a[i], "mouseup", clicky.click);
}
} else {
clicky.add_event(a[i], "mouseup", clicky.outbound);
}
}
}
}
}};
clicky.init();