例子,js判断浏览器类型。
function UA() {
var browsertype = "";
function c(browser) {
return navigator.userAgent.toLowerCase().indexOf(browser) > -1;
}
return browsertype = c('opera') === true ? 'opera': (c('msie') && c('360se')) === true ? '360se': ((c('msie') && c('tencenttraveler')) && c('metasr')) === true ? "sogobrowser": (c('msie') && c('qqbrowser')) === true ? "QQbrowser": (c('msie') && c('tencenttraveler')) === true ? "TTbrowser": c('msie') === true ? 'msie': (c('safari') && !c('chrome')) === true ? 'safari': c('maxthon') === true ? "maxthon": ((c('chrome') && c('safari')) && c('qihu 360ee')) === true ? "360ee": (c('chrome') && c('taobrowser')) === true ? "taobrowser": c('chrome') === true ? "chrome": ((c('gecko') && !c('webkit')) && c('seamonkey')) === true ? "SeaMonkey": ((c('gecko') && !c('webkit')) && !c('netscape')) === true ? 'firefox': ((c('gecko') && !c('webkit')) && c('netscape')) === true ? 'netscape': "other";
}
//document.write(navigator.userAgent.toLowerCase()+"<br/>")
if (UA().toLowerCase() == "firefox" || UA().toLowerCase() == "seamonkey") {
document.write("你正在使用:" + UA().toLowerCase() + navigator.userAgent.toLowerCase().substring(navigator.userAgent.toLowerCase().lastIndexOf("/")) + "<br/>");
} else if (UA().toLowerCase() == "opera") {
document.write("你正在使用:" + UA().toLowerCase() + navigator.userAgent.toLowerCase().substring(navigator.userAgent.toLowerCase().lastIndexOf("/")) + "<br/>");
} else if (UA().toLowerCase() == "netscape") {
document.write("你正在使用:" + UA().toLowerCase() + navigator.userAgent.toLowerCase().substring(navigator.userAgent.toLowerCase().lastIndexOf("/"), navigator.userAgent.toLowerCase().lastIndexOf(" ")) + "<br/>");
} else if (UA().toLowerCase() == "taobrowser") {
document.write("你正在使用:" + UA().toLowerCase() + navigator.userAgent.toLowerCase().substring(navigator.userAgent.toLowerCase().lastIndexOf("/")) + "<br/>");
} else if (UA().toLowerCase() == "qihu 360ee") {
document.write("你正在使用:" + UA().toLowerCase());
} else if (UA().toLowerCase() == "safari") {
document.write("你正在使用:" + UA().toLowerCase() + navigator.userAgent.toLowerCase().substring(navigator.userAgent.toLowerCase().lastIndexOf("/")) + "<br/>");
} else if (UA().toLowerCase() == "chrome") {
document.write("你正在使用:" + navigator.userAgent.toLowerCase().substring(navigator.userAgent.toLowerCase().lastIndexOf(UA().toLowerCase()), navigator.userAgent.toLowerCase().lastIndexOf(" ")) + "<br/>");
} else if (UA().toLowerCase() == "maxthon") {
document.write("你正在使用:" + navigator.userAgent.toLowerCase().substring(navigator.userAgent.toLowerCase().lastIndexOf(UA().toLowerCase()), navigator.userAgent.toLowerCase().lastIndexOf('chrome')) + "<br/>");
} else if (UA().toLowerCase() == "360se") {
document.write("你正在使用:" + UA().toLowerCase());
} else if (UA().toLowerCase() == "qqbrowser") {
document.write("你正在使用:" + UA().toLowerCase() + navigator.userAgent.toLowerCase().substring(navigator.userAgent.toLowerCase().lastIndexOf("/")) + "<br/>");
} else if (UA().toLowerCase() == "ttbrowser") { www.jb200.com
document.write("你正在使用:" + UA().toLowerCase() + navigator.userAgent.toLowerCase().substring(navigator.userAgent.toLowerCase().lastIndexOf(" "), navigator.userAgent.toLowerCase().lastIndexOf(")")) + "<br/>");
} else if (UA().toLowerCase() == "msie") {
document.write("你正在使用:" + navigator.userAgent.toLowerCase().substring(navigator.userAgent.toLowerCase().lastIndexOf(UA().toLowerCase())).substring(0, navigator.userAgent.toLowerCase().substring(navigator.userAgent.toLowerCase().lastIndexOf(UA().toLowerCase())).indexOf(";")) + "<br/>");
} else {
document.write("你正在使用:" + UA().toLowerCase());
}
UA();