js检测浏览器版本是否需要更新? 我开发了一个小型网站,在win7+IE8+mysql+php 测试环境下开发,在IE8以下浏览器中会出现一些小问题,所以我想检测用户浏览器是否低于IE8,如果低于IE8就提示用户下载更新!只测试IE浏览器就行,其他类型的不用检测。各位大神给点代码! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这本身属于js的范畴。我们不太懂。http://www.google.com.hk/#hl=zh-CN&source=hp&q=js%E6%A3%80%E6%B5%8B%E6%B5%8F%E8%A7%88%E5%99%A8%E7%89%88%E6%9C%AC&oq=js%E6%A3%80%E6%B5%8B%E6%B5%8F%E8%A7%88%E5%99%A8%E7%89%88%E6%9C%AC&aq=f&aqi=&aql=&gs_sm=e&gs_upl=78373l85897l0l86202l7l7l0l0l0l0l0l0ll0l0&bav=cf.osb&fp=576c85655706e230&biw=1920&bih=976 IE8正常IE9未必正常。关于js判断浏览器类型,网上很多资料。 <?php echo $_SERVER["HTTP_USER_AGENT"]; ?>得到浏览器的信息 你再做判断 //判断下面字符串,当然对恶意用户无效echo $_SERVER['HTTP_USER_AGENT'];会得到如下值 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Alexa Toolbar),判断MISE 后面的6.0是否符合要求应该就可以了,当然JS也是一样. 做兼容太费时了,我的站点在校内使用,90%都是IE浏览器。比如我得到浏览器信息如下:Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2)那么我如何与IE8进行比较呢? http://www.w3school.com.cn/tiy/t.asp?f=hdom_browserdetailschrome浏览器的用户代理报头:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1firefox浏览器的用户代理报头:Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1IE系列浏览器的用户代理报头:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.3)IE的根据indexOf找是否有MSIE,然后取后面的7.0/6.0/8.0 JS检测agent中浏览器信息即可。但作CSS兼容才是正道。用户都很反感让下载软件才能使用的提示,你会为你的“自以为无妨”而失去很多用户。 CSS兼容是有点麻烦,但如果没必要,谁还会去麻烦地去学麻烦地去做呢。 function Browser(){ this.Opera = window.opera ? true : false; this.IE = document.all && !this.Opera ? true : false; this.IE6 = this.IE && typeof(window.XMLHttpRequest) == "undefined" ? true : false; this.IE8 = this.IE && typeof(document.querySelectorAll) != "undefined" ? true : false; this.IE7 = this.IE && ! this.IE6 && !this.IE8 ? true : false; this.WebKit = /WebKit/i.test(navigator.userAgent) ? true : false, this.iPhone = /iPhone|iPod/i.test(navigator.userAgent)? true : false; this.Chrome = /Chrome/i.test(navigator.userAgent) ? true : false; this.Safari = /Safari/i.test(navigator.userAgent) && !this.Chrome ? true : false; this.Konqueror = navigator.vendor == "KDE" ? true : false; this.Konqueror4 = this.Konqueror && /native code/.test(document.getElementsByClassName) ? true : false; this.Gecko = !this.WebKit && navigator.product == "Gecko" ? true : false; this.Gecko19 = this.Gecko && Array.reduce ? true : false;}var browser = new Browser();if(!browser.IE8) { alert("你的浏览器不是IE 8");} 不是IE8的,也可能是CHROME,FF。所以应该是发现是IE6/7的,建议升级到IE8。可是使用IE作内核扩展性浏览器很多,而它们都把navigator.userAgent改了。直接取navigator.userAgent判断是不可靠的。不过上楼的方法是取IE内核所支持的方法,还是比较可靠的。只需要把最后面的逻辑改一下:var browser = new Browser();if(browser.IE6||browser.IE7) { alert("你的IE浏览器版本太低,请升级到IE8");} 下面是更为简便的方法:<!--[if lt IE 8]><script>alert('低于IE8不能正常使用本站,建议升级。')</script><![endif]--> js特性问题 ,请教大家了, Ext 实用回车 用过jquery.autocomplete.js的请进 一个老问题,js 多级树菜单 一个关于二级菜单文字换图片不能自动跳的问题,请高手指点,急! 在线等待,有关js文件调用的问题 请问这段为何只能在IE下跑,不能在360、Chrome下跑?请指正! 字符串作为参数的时候,有长度限制吗? 为什么返回前一页时输入的内容会被清空? 在那里怎么没有权限 javascript canvas的跨域问题 jquery 关于插件自动补充以及trigger手动触发事件紧急!!跪求高手解答疑问
http://www.google.com.hk/#hl=zh-CN&source=hp&q=js%E6%A3%80%E6%B5%8B%E6%B5%8F%E8%A7%88%E5%99%A8%E7%89%88%E6%9C%AC&oq=js%E6%A3%80%E6%B5%8B%E6%B5%8F%E8%A7%88%E5%99%A8%E7%89%88%E6%9C%AC&aq=f&aqi=&aql=&gs_sm=e&gs_upl=78373l85897l0l86202l7l7l0l0l0l0l0l0ll0l0&bav=cf.osb&fp=576c85655706e230&biw=1920&bih=976
<?php echo $_SERVER["HTTP_USER_AGENT"]; ?>得到浏览器的信息 你再做判断
//判断下面字符串,当然对恶意用户无效
echo $_SERVER['HTTP_USER_AGENT'];
会得到如下值 Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; Alexa Toolbar),
判断MISE 后面的6.0是否符合要求应该就可以了,当然JS也是一样.
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2)
那么我如何与IE8进行比较呢?
浏览器的用户代理报头:Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.202 Safari/535.1firefox
浏览器的用户代理报头:Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1IE系列浏览器的用户代理报头:Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; InfoPath.3)IE的根据indexOf找是否有MSIE,然后取后面的7.0/6.0/8.0
但作CSS兼容才是正道。用户都很反感让下载软件才能使用的提示,你会为你的“自以为无妨”而失去很多用户。
this.Opera = window.opera ? true : false;
this.IE = document.all && !this.Opera ? true : false;
this.IE6 = this.IE && typeof(window.XMLHttpRequest) == "undefined" ? true : false;
this.IE8 = this.IE && typeof(document.querySelectorAll) != "undefined" ? true : false;
this.IE7 = this.IE && ! this.IE6 && !this.IE8 ? true : false;
this.WebKit = /WebKit/i.test(navigator.userAgent) ? true : false,
this.iPhone = /iPhone|iPod/i.test(navigator.userAgent)? true : false;
this.Chrome = /Chrome/i.test(navigator.userAgent) ? true : false;
this.Safari = /Safari/i.test(navigator.userAgent) && !this.Chrome ? true : false;
this.Konqueror = navigator.vendor == "KDE" ? true : false;
this.Konqueror4 = this.Konqueror && /native code/.test(document.getElementsByClassName) ? true : false;
this.Gecko = !this.WebKit && navigator.product == "Gecko" ? true : false;
this.Gecko19 = this.Gecko && Array.reduce ? true : false;
}var browser = new Browser();
if(!browser.IE8) {
alert("你的浏览器不是IE 8");
}
所以应该是发现是IE6/7的,建议升级到IE8。可是使用IE作内核扩展性浏览器很多,而它们都把navigator.userAgent改了。直接取navigator.userAgent判断是不可靠的。不过上楼的方法是取IE内核所支持的方法,还是比较可靠的。只需要把最后面的逻辑改一下:
var browser = new Browser();
if(browser.IE6||browser.IE7) {
alert("你的IE浏览器版本太低,请升级到IE8");
}
<!--[if lt IE 8]>
<script>alert('低于IE8不能正常使用本站,建议升级。')</script>
<![endif]-->