<!DOCTYPE HTML>
<html>
<head>
<title>navigator对象常用属性</title>
<meta charset="utf-8" />
</head>
<body>
<script>
if(navigator.cookieEnabled){
document.write("已启用cookie")
}else{
document.write("已禁用cookie")
}
if(navigator.plugins["Shockwave Flash"]===undefined){
document.write("<h3>未安装flash插件,</h3><a href='#'>点此安装</a><br>")
}else{
document.write("已成功安装flash插件<br>")
}
document.write(navigator.userAgent)
var ua=navigator.userAgent;
var browser,version;
//获取浏览器的名称
if(ua.indexOf("Firefox")!=-1){
browser="Firefox"
}else if(ua.indexOf("Trident")!=-1){
browser="IE";
if(ua.indexOf("IE")==-1){
version=11;
}
}else if(ua.indexOf("OPR")!=-1){
browser="OPR"
}else if(ua.indexOf("Edge")!=-1){
browser="Edge"
}else if(ua.indexOf("Chrome")!=-1){
browser="Chrome"
}else if(ua.indexOf("Safari")!=-1){
browser="Safari"
}else{
browser="未知浏览器";
}
//获取浏览器的版本号
document.write("<h1>"+browser+"</h1>");
if(version===undefined){
var i=ua.indexOf(browser);
i=i+browser.length+1;
version=parseInt(ua.slice(i,i+3));
console.log(version)
}
document.write("<h1>"+version+"</h1>");
</script>
</body>
</html>
获取当前浏览器名称和版本信息
最新推荐文章于 2024-08-20 22:06:42 发布