1. This website uses cookies. By continuing to use this website you are giving consent to cookies being used.
    For information on cookies and how you can disable them visit our Cookie Usage page.
    Dismiss Notice

JavaScript IE vs FF and others.

Discussion in 'Web Development' started by bohica032, Apr 16, 2007.

  1. bohica032

    bohica032 New Member

    Good Day to all.

    Here is a piece of code that my be helpfull to some. This code determines if your visitor is using IE or FF and others. At the same time it will determine which CSS file to attach to your pages. This way you can create 2 css files, one specific to IE only and other that works the best for FF and other browsers.

    I hope it will work for you.
    Code:
    <script language="JavaScript">
    <!--
    browser_version= parseInt(navigator.appVersion);
    browser_type = navigator.appName;
     
    if (browser_type == "Microsoft Internet Explorer" && (browser_version >= 4)) {
    document.write("<link rel='stylesheet' type='text/css' href='css/main_IE.css' />");
    }
     
    else {
    document.write("<link REL='stylesheet' HREF='css/main.css' TYPE='text/css' />");
    }
    // --></script>
     
  2. Scoooooty

    Scoooooty Member

    Nice script
     
  3. solemage

    solemage New Member

    Nice job, I might use this.
     
  4. kalnera

    kalnera New Member

    HTML:
    <script language="JavaScript">
    <!--
    browser_version= parseInt(navigator.appVersion);
    browser_type = navigator.appName;
     
    if (browser_type == "Microsoft Internet Explorer" && (browser_version >= 4)) {
    document.write("<link rel='stylesheet' type='text/css' href='css/main_IE.css' />");
    }
    else if (browser_type == "Mozila firefox" && (browser_version >= 4)) {
    document.write("<link rel='stylesheet' type='text/css' href='css/main_mf.css' />");
    } 
     
    else {
    document.write("<link REL='stylesheet' HREF='css/main.css' TYPE='text/css' />");
    }
    // --></script>
    would this be proper code for taking into consideration firefox also? I am not sure what is the name to call for firefox so... :). I am having troulbe with different look on IE and opera while look on firefox is good :)
     
  5. Anders Moen

    Anders Moen New Member

    bohica032:
    And this would be if a user has disabled JS? ;)

    It's better to use PHP (if you use PHP as server-side language on your site) to check what browser users is using
     
  6. unixanalyst

    unixanalyst New Member

    Looky looky what I found...

    Conditional comments, read only by IE to solve this just problem:

    <!--[if IE]>
    <link href="iestyle.css" rel="stylesheet" type="text/css" media="screen" />
    <![endif]-->

    Works for MSIE5.5+