首页 » JavaScript » JavaScript判断浏览器类型型号代码示例

JavaScript判断浏览器类型型号代码示例

原文 http://blog.csdn.net/qq_35661171/article/details/79256927

2018-02-06 02:00:04阅读(342)

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>My JSP 'M.jsp' starting page</title>
<SCRIPT language="JavaScript">
function myexplorer() {
var explorer = window.navigator.userAgent;
if (explorer.indexOf("QQBrowser") >= 0 || explorer.indexOf("QQ") >= 0) {
return myexplorer = "腾讯QQ";
} else if (explorer.indexOf("Safari") >= 0 && explorer.indexOf("MetaSr") >= 0) {
return myexplorer = "搜狗";
} else if (!!window.ActiveXObject || "ActiveXObject" in window) { //IE
if (!window.XMLHttpRequest) {
return myexplorer = "IE6";
} else if (!-[ 1, ] && document.documentMode && !("msDoNotTrack" in window.navigator)) {
return myexplorer = "IE8";
} else { //IE9 10 11
var hasStrictMode = (function() {
"use strict";return this === undefined;
}());
if (hasStrictMode) {
if (!!window.attachEvent) {
return myexplorer = "IE10";
} else {
return myexplorer = "IE11";
}
} else {
return myexplorer = "IE9";
}
}
} else { //非IE
if (explorer.indexOf("LBBROWSER") >= 0) {
return myexplorer = "猎豹";
} else if (explorer.indexOf("360ee") >= 0) {
return myexplorer = "360极速浏览器";
} else if (explorer.indexOf("360se") >= 0) {
return myexplorer = "360安全浏览器";
} else if (explorer.indexOf("se") >= 0) {
return myexplorer = "搜狗浏览器";
} else if (explorer.indexOf("aoyou") >= 0) {
return myexplorer = "遨游浏览器";
} else if (explorer.indexOf("qqbrowser") >= 0) {
return myexplorer = "QQ浏览器";
} else if (explorer.indexOf("baidu") >= 0) {
return myexplorer = "百度浏览器";
} else if (explorer.indexOf("Firefox") >= 0) {
return myexplorer = "火狐";
} else if (explorer.indexOf("Maxthon") >= 0) {
return myexplorer = "遨游";
} else if (explorer.indexOf("Chrome") >= 0) {
return myexplorer = "谷歌(或360伪装)";
} else if (explorer.indexOf("Opera") >= 0) {
return myexplorer = "欧朋";
} else if (explorer.indexOf("TheWorld") >= 0) {
return myexplorer = "世界之窗";
} else if (explorer.indexOf("Safari") >= 0) {
return myexplorer = "苹果";
} else {
return myexplorer = "其他";
}
}
}
</script>
</head>
<body>
<script>document.write("浏览器型号:"+myexplorer());</script>
</body>

</html>

将项目部署到tomcat服务器中,启动访问就会显示当前浏览该网页浏览器的型号了.感谢你的支持,谢谢!

最新发布

CentOS专题

关于本站

5ibc.net旗下博客站精品博文小部分原创、大部分从互联网收集整理。尊重作者版权、传播精品博文,让更多编程爱好者知晓!

小提示

按 Ctrl+D 键,
把本文加入收藏夹