判断浏览器版本并给出升级提示

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/jbguo/article/details/82258375
(function (window) {
   function getBrowserInfo () {
    var agent = navigator.userAgent.toLowerCase()
    var regStrff = /firefox\/[\d.]+/gi
    if (agent.indexOf('firefox') > 0) {
      return agent.match(regStrff)
    }
  }
  var browser = getBrowserInfo()
  var verinfo = (browser + '').replace(/[^0-9.]/ig, '')
  var theUA = window.navigator.userAgent.toLowerCase()
  if ((theUA.match(/msie\s\d+/) && theUA.match(/msie\s\d+/)[0]) || (theUA.match(/trident\s?\d+/) && theUA.match(/trident\s?\d+/)[0])) {
    var ieVersion = theUA.match(/msie\s\d+/)[0].match(/\d+/)[0] || theUA.match(/trident\s?\d+/)[0]
    if (ieVersion < 9 || verinfo < '56') {
      var str = '你的浏览器版本太low了,已经和时代脱轨了 :( ' var str2 = "推荐使用:<a href='https://www.baidu.com/s?ie=UTF-8&wd=%E8%B0%B7%E6%AD%8C%E6%B5%8F%E8%A7%88%E5%99%A8' target='_blank' style='color:blue;'>谷歌</a>" document.writeln("<pre style='text-align:center;color:#fff;background-color:#0cc; height:100%;border:0;position:fixed;top:0;left:0;width:100%;z-index:1234'>" + "<h2 style='padding-top:200px;margin:0'><strong>" + str + '<br/></strong></h2><h2>' + str2 + '</h2></pre>') document.execCommand('Stop') } } }(window))

判断ie版本

<!doctype html>
<!--[if IE 6]><html lang="en" class="ielt7  ielt8  ielt9 ielt10 en"><![endif]-->
<!--[if IE 7]><html lang="en" class="ie7  ielt8  ielt9 ielt10 en"><![endif]-->
<!--[if IE 8 ]><html lang="en" class="ie8 ielt9 ielt10 en"><![endif]-->
<!--[if IE 9 ]><html lang="en" class="ie9 ielt10 en"><![endif]-->
<!--[if (gt IE 9)|!(IE)]><!--><html lang="en" class=" en"><!--<![endif]-->
根据浏览器选择jquery版本
        <!--[if lt IE 9]>
<script src="http://www.to8to.com/gb_js/jquery-1.9.1.min.js" type="text/javascript"></script>
<![endif]-->
<!--[if gte IE 9]> 
<script src="http://www.to8to.com/gb_js/jquery-1.10.2.min.js" type="text/javascript"></script>
<![endif]-->
<!--[if !IE]><!-->
<script src="http://www.to8to.com/gb_js/jquery-1.10.2.min.js" type="text/javascript"></script>
<!--<![endif]-->

猜你喜欢

转载自blog.csdn.net/jbguo/article/details/82258375