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

来源:互联网 发布:秦朝是如何灭亡的 知乎 编辑:程序博客网 时间:2024/06/05 15:43

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")}
0 0
原创粉丝点击