代码如下:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
</head>
<body>
<script type="text/javascript">
function myBrowser(){
var userAgent = navigator.userAgent//取得浏览器的userAgent字符串
console.log(userAgent)
var isOpera = userAgent.indexOf("Opera") >-1
if (isOpera) {
return "Opera"
}//判断是否Opera浏览器
if (userAgent.indexOf("Firefox") >-1) {
return "FF"
} //判断是否Firefox浏览器
if (userAgent.indexOf("Chrome") >-1){
return "Chrome"
}
if (userAgent.indexOf("compatible") >-1 &&userAgent.indexOf("MSIE") >-1 &&!isOpera) {
return "IE"
}//判断是否IE浏览器
}
var cc = myBrowser()
if(cc == "Chrome"){
alert("当前是Chrome浏览器")
}
if(cc == "IE"){
alert("当前是IE浏览器")
}
</script>
</body>
</html>
代码如下:
<html><head>
<title>JS显示当前浏览器详细信息</title>
<SCRIPT>
function whatBrowser()
{
document.Browser.Name.value=navigator.appName
document.Browser.Version.value=navigator.appVersion
document.Browser.Code.value=navigator.appCodeName
document.Browser.Agent.value=navigator.userAgent
if (window.navigator.userAgent.indexOf('compatible') != -1) {
alert('360兼容模式')
}
if(window.navigator.userAgent.indexOf('AppleWebKit') != -1) {
alert('360极速模式')
}
}
</SCRIPT>
<TABLE BORDER>
</head>
<body bgcolor="#fef4d9" onLoad="whatBrowser()">
<FORM NAME="Browser">
<TR> <TD> 名称: </TD> <TD>
<INPUT TYPE="txt" NAME="Name" Size="150"></TD> </TR>
<TR> <TD> 版本: </TD> <TD> <INPUT TYPE="txt" NAME="Version" Size="150"></TD> </TR> <TR> <TD> 内核: </TD>
<TD> <INPUT TYPE="txt" NAME="Code" Size="150"></TD>
</TR> <TR> <TD> User-Agent: </TD>
<TD> <INPUT TYPE="txt" NAME="Agent" Size="150"></TD>
</TR>
</FORM>
</TABLE>
</body>
</html>