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
- JS检测用户使用哪种浏览器
- 浏览器检测(BrowserDetect.js)使用
- 浏览器检测(BrowserDetect.js)使用
- js检测当前使用的浏览器
- adblockTester通过js检测用户浏览器是否安装了AdBlock
- 浏览器用户代理检测
- js判断用户使用的是什么浏览器
- JS判断用户使用的浏览器类型
- 脚本-浏览器内核判断和用户使用哪种浏览器
- 检测浏览器的js
- js检测浏览器版本
- JS检测手机浏览器
- js 检测浏览器版本
- JS浏览器检测
- js 浏览器检测
- js检测浏览器代码
- JS检测浏览器插件
- js检测浏览器版本
- JS的冒泡和捕获
- 第12课: 、<hr>标签添加水平横线
- DRBD+Heartbeat+NFS高可用图文实操
- 解决易语言程序Not found the kernel library or the kernel library is invalid问题
- Mysql主从复制
- JS检测用户使用哪种浏览器
- 指南
- Extjs 二级联动
- Android Support Library
- HTML CSS学习历程
- linux常用命令
- CodeForces 625B War of the Corporations(KMP)
- Spark和Anaconda结合
- http://blog.csdn.net/sinyu890807/article/details/51933728