<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<h1>浏览器的类型</h1>
<hr>
<script>
document.write("userAgent : "+navigator.userAgent+'<br>');
function uaMatch( ua ){
var match = /(chrome)\/([\w.]+)/i.exec(ua) ||
/(Firefox)\/([\w.]+)/i.exec(ua) ||
/(MSIE) ([\w.]+)/i.exec(ua) ||
ua.indexOf('Trident') >= 0 && /(rv):([\w.]+)/i.exec(ua) ||
/(Webkit)[ \/]([\w.]+)/i.exec(ua) ||
/(Gecko)[ \/]([\w.]+)/i.exec(ua);
//console.log(match);
return {
"browser":match[1],
"version":match[2]
};
}
var v = uaMatch(navigator.userAgent);
document.write('浏览器名 : '+v.browser+'<br>');
document.write('浏览器版本 : '+v.version+'<br>');
</script>
</body>
</html>
网友评论