读取浏览器版本的JS函数(支持IE/FF/OP/SF/CHROME/NS)
2009-6-20 14:41:59 | At WEB开发 | Comments 0 | View 420
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="zh-cn" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>无标题 1</title>
</head>
<body>
<label id="Label1"></label>
<script type="text/javascript">
function getBrowser(){
var bro = navigator.userAgent.toLowerCase();
if(/msie/.test(bro)) return 'IE' + bro.match(/msie ([\d.]*);/)[1]
else if(/navigator/.test(bro)) return 'NS' + bro.match(/navigator\/([\d.]*)/)[1]
else if(/chrome/.test(bro)) return 'CR' + bro.match(/chrome\/([\d]*)/)[1]
else if(/safari/.test(bro)) return 'SF' + bro.match(/version\/([\d]*)/)[1]
else if(/opera/.test(bro)) return 'OP' + bro.match(/version\/([\d]*)/)[1]
else if(/firefox/.test(bro)) return 'FF' + bro.match(/firefox\/([\d]*)/)[1]
}
document.getElementById('Label1').innerHTML = getBrowser();
</script>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="zh-cn" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>无标题 1</title>
</head>
<body>
<label id="Label1"></label>
<script type="text/javascript">
function getBrowser(){
var bro = navigator.userAgent.toLowerCase();
if(/msie/.test(bro)) return 'IE' + bro.match(/msie ([\d.]*);/)[1]
else if(/navigator/.test(bro)) return 'NS' + bro.match(/navigator\/([\d.]*)/)[1]
else if(/chrome/.test(bro)) return 'CR' + bro.match(/chrome\/([\d]*)/)[1]
else if(/safari/.test(bro)) return 'SF' + bro.match(/version\/([\d]*)/)[1]
else if(/opera/.test(bro)) return 'OP' + bro.match(/version\/([\d]*)/)[1]
else if(/firefox/.test(bro)) return 'FF' + bro.match(/firefox\/([\d]*)/)[1]
}
document.getElementById('Label1').innerHTML = getBrowser();
</script>
</body>
</html>
[由 azhi 于 2009-6-20 14:41:59 最后编辑]
近期相关评论
发表评论
正在载入数据...