PHP/HTML/CSS - If FireFox, If Chrome, If Safari

后端 未结 4 548
迷失自我
迷失自我 2021-02-04 07:32

Is there a simple conditional statement, css command, html, jquery, javascript or simple PHP dynamic way of detecting the current browser?


           


        
4条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-04 07:42

    With CSS there is no way you can achieve browser detection. However with PHP, ASP and other programming languages you can get browser detection within the page. I am not here to tell you the pro or cons about it - I take it you know about the bad and good about browser detection and web standards but here is the list.

    PHP solution.

    if(isset($_SERVER['HTTP_USER_AGENT'])){
        $agent = $_SERVER['HTTP_USER_AGENT'];
    }
    

    Then, compare it to what you want

    For compare with, for example "firefox" you should do:

    if(strlen(strstr($agent,"Firefox")) > 0 ){      
        $browser = 'firefox';
    }
    if($browser=='firefox'){
        echo '