Show a message if the browser is not internet explorer 9 or greater

后端 未结 10 1346
北恋
北恋 2020-12-31 01:18

I would like to show my users a bar that looks like this, if:

  1. Browser is not IE; or
  2. Browser is IE but is version 8 or earlier

10条回答
  •  南笙
    南笙 (楼主)
    2020-12-31 01:30

    I don't suggest you to use client side as some browsers might trick you by passing wrong values to pass website tests.

    So i guess your using PHP as a server side you can detect the browser using the get_browser() function that give you a lot of information about the browser here is a nice turtoeial:

    Part 1:

    http://thenewboston.org/watch.php?cat=11&number=67

    Part 2:

    http://thenewboston.org/watch.php?cat=11&number=68

    if your using another language all server side language has this functunality just google it or reference some sort of a turtorial

    From the client side you can detect if it is compatible like that:

    function Is_Compatible(){
    var browser = navigator.appName;
    var Fvar = document.getElementById('test').style.borderRadius;
    if(browser !== 'Microsoft Internet Explorer'){
    return false;
    }
    if(Fvar == undefined){
    //Not IE9+
    return false;
    }else{
    //Is IE9+
    return true;
    }
    }
    if(Is_Compatible() == true){
    alert('Compatible');
    }else{
    alert('uncompatible');
    }
    

    HTML:

    FIDDLE:

    Test it and it works:

    http://jsfiddle.net/Z7fvb/

提交回复
热议问题