Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jul 2009
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile How to Detect A Browser

    I want to set up my website so it is compatible with all browsers and older versions of IE. So far in order to detect browsers and which version, I have this snippet of code...

    <script type="text/javascript">
    var browser=navigator.appName;
    var b_version=navigator.appVersion;
    var version=parseFloat(b_version);
    </script>

    Ultimately what I want it to do is detect which browser is loading the page and after it determines which browser it will call up the appropriate CSS file to make sure it looks right in the browser.

    In other words the code would say...

    if the browser is Firefox, then load this css file
    if the browser is IE but the version is less than 7, then load this cascading style sheet.

    I just don't know how to code this appropriately,

    Thanks!

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,982
    Thanks
    203
    Thanked 2,536 Times in 2,514 Posts
    http://www.javascriptkit.com/javatut...jdetect3.shtml


    Code:
    <!--[if lte IE 6]>
    <link rel="stylesheet" type="text/css" href="IEspecific.css" />
    <![endif]-->
    
    <!--[if !IE]>
    <link rel="stylesheet" type="text/css" href="allbutIE.css" />
    <![endif]-->
    What about IE7+?

    It is your responsibility to die() if necessary….. - PHP Manual
    Last edited by Philip M; 07-15-2009 at 08:22 AM.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •