Discuz教程网

用JS判别浏览器种类以及IE版本的几种方法小结

[复制链接]
authicon dly 发表于 2011-9-14 08:29:23 | 显示全部楼层 |阅读模式
  1. var isIE=!!window.ActiveXObject;
  2. var isIE6=isIE&&!window.XMLHttpRequest;
  3. var isIE8=isIE&&!!document.documentMode;
  4. var isIE7=isIE&&!isIE6&&!isIE8;
  5. if (isIE){
  6. if (isIE6){
  7. alert("ie6");
  8. }else if (isIE8){
  9. alert("ie8");
  10. }else if (isIE7){
  11. alert("ie7");
  12. }
  13. }
复制代码

--------------------------------------------------------------------------------
  1. if(navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.match(/6./i)=="6."){
  2. alert("IE 6");
  3. }
  4. else if(navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.match(/7./i)=="7."){
  5. alert("IE 7");
  6. }
  7. else if(navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.match(/8./i)=="8."){
  8. alert("IE 8");
  9. }
  10. else if(navigator.appName == "Microsoft Internet Explorer" && navigator.appVersion.match(/9./i)=="9."){
  11. alert("IE 9");
  12. }
复制代码

--------------------------------------------------------------------------------
  1. if(navigator.userAgent.indexOf("Opera") != -1) {
  2. alert('Opera');
  3. }
  4. else if(navigator.userAgent.indexOf("MSIE") != -1) {
  5. alert('Internet Explorer');
  6. }
  7. else if(navigator.userAgent.indexOf("Firefox") != -1) {
  8. alert('Firefox');
  9. }
  10. else if(navigator.userAgent.indexOf("Netscape") != -1) {
  11. alert('Netscape');
  12. }
  13. else if(navigator.userAgent.indexOf("Safari") != -1) {
  14. alert('Safari');
  15. }
  16. else{
  17. alert('无法识别的浏览器。');
  18. }
复制代码


--------------------------------------------------------------------------------
  1. if(!+'\v1' && !'1'[0]){
  2. alert("ie6或ie7")
  3. }
复制代码




上一篇:JS 控制小数位数的实现代码
下一篇:JQuery+JS实现仿百度搜索结果中关键字变色效果
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-2 06:52

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表