JS检测用户使用哪种浏览器

JS检测

<html>
<head>
    <title>JavaScript检测浏览器</title>
</head>
<body>
<script type="text/javascript">
    var userAgent=navigator.userAgent.toLowerCase(), s, o = {};   
    var browser={
        version:(userAgent.match(/(?:firefox|opera|safari|chrome|msie)[\/: ]([\d.]+)/))[1],
        safari:/version.+safari/.test(userAgent),
        chrome:/chrome/.test(userAgent),
        firefox:/firefox/.test(userAgent),
        ie:/msie/.test(userAgent),
        opera: /opera/.test(userAgent ) 
    } /* 获得浏览器的名称及版本信息 */

    if (browser.ie && browser.version > 6)
    {
      /* 判断是否为IE 6以上版本,是则执行以下操作 */
      document.writeln("<p>您使用的是IE "+browser.version+"<\/p>");
    }
</script>
</body>
</html>
if (browser.safari) {}  /* 判断是否为safari */
if (browser.firefox) {} /* 判断是否为firefox */
if (browser.chrome) {}  /* 判断是否为chrome */
if (browser.opera) {}   /* 判断是否为opera */
if (browser.ie) {}      /* 判断是否为IE */

亲测可行^_^

PHP检测

<html>
<head>
    <title>PHP 浏览器检测</title>
</head>
<body>
<?php if(strstr($_SERVER["HTTP_USER_AGENT"], "MSIE") ) : ?>

<!-- 这里就填上你要在IE中执行的html代码吧 -->

<?php endif; ?>
</body>
</html>
<?php if(strstr($_SERVER["HTTP_USER_AGENT"], "MSIE 8.0") ) : ?>     
/* IE 8 */
<?php if(strstr($_SERVER["HTTP_USER_AGENT"], "MSIE 7.0") ) : ?>    
/* IE 7 */
<?php if(strstr($_SERVER["HTTP_USER_AGENT"], "MSIE 6.0") ) : ?>     
/* IE 6 */
<?php if(strstr($_SERVER["HTTP_USER_AGENT"], "NetCaptor") ) : ?>    
/* Netscape */
<?php if(strstr($_SERVER["HTTP_USER_AGENT"], "Netscape") ) : ?>     
/* Netscape */
<?php if(strstr($_SERVER["HTTP_USER_AGENT"], "Lynx") ) : ?>         
/* Lynx */
<?php if(strstr($_SERVER["HTTP_USER_AGENT"], "Opera") ) : ?>       
 /* Opera */
<?php if(strstr($_SERVER["HTTP_USER_AGENT"], "Konqueror") ) : ?>    
/* Konqueror */
<?php if(strstr($_SERVER["HTTP_USER_AGENT"], "Mozilla/5.0") ) : ?>  
/* Mozilla/5.0 */
<?php if(strstr($_SERVER["HTTP_USER_AGENT"], "Firefox") ) : ?>  
/* Firefox */
<?php if(strstr($_SERVER["HTTP_USER_AGENT"], "Firefox/3") ) : ?>  
/* Firefox 3.0*/
<?php if(strstr($_SERVER["HTTP_USER_AGENT"], "Firefox/2") : ?>  
/* Firefox 2.0 */
<?php if(strstr($_SERVER["HTTP_USER_AGENT"], "Chrome") : ?>  
/* Chrome */
<?php if(strstr($_SERVER["HTTP_USER_AGENT"], "MSIE 6.0") ) : ?>  
<script type="text/javascript">
  alert("还在用Internet Explorer 6 ? 你OUT了,赶快升级吧!")
</script>
<?php endif; ?>

the other way 判断浏览器类别

var Sys={};
var ua=naivigator.userAgent.toLowerCase();
if(window.ActiveXobject)
Sys.ie=ua.match(/msie([\d.]+)/)[1]
else if(doucument.getBoxObjectFor)
Sys.firefox=ua.match(\firefox([\d.]+)/)[1]
else if(window.MessageEvent&&!doucument.getBoxObjectFor)
Sys.chrome=ua.match(\chrome([\d.]+)/)[1]
else if(window.opera)
Sys.opera=ua.match(\opera.([\d.]+)/)[1]
else if(window.openDatabase)
Sys.safari=ua.match(\version([\d.]+)/)[1]
if(document.getBoxObjectFor){
     debugger;
     alert("我是firefox")
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值