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 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jul 2009
    Posts
    152
    Thanks
    8
    Thanked 0 Times in 0 Posts

    some code of making a condition to the IE browser?

    Code:
     if (navigator.appName == "Microsoft Internet Explorer") {
    begin = navigator.userAgent.indexOf("MSIE ") +
    "MSIE ".length;
    if(navigator.userAgent.indexOf(";", begin) > 0) {
    end = navigator.userAgent.indexOf(";", begin);
    } else {
    end = navigator.userAgent.indexOf(")", begin)
    + 2;
    }
    document.getElementById("targetDiv").innerHTML =
    "You are using Internet Explorer " +
    navigator.userAgent.substring(begin, end);
    }
    }
    i don't know why there added an else part? what's the meaning and effect of it? thank you,

  • #2
    Regular Coder
    Join Date
    Jun 2002
    Location
    Flint, Michigan, USA
    Posts
    629
    Thanks
    1
    Thanked 20 Times in 20 Posts
    How about something much simpler:
    Code:
    <!--[if IE]>
      <p>You are using Internet Explorer.  How sad.</p>
    <![endif]-->

  • #3
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    +1 to jalarie
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • #4
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    27,160
    Thanks
    80
    Thanked 4,559 Times in 4,523 Posts
    LOL! Too true!

    But to answer his question:

    APPARENTLY (and this is only from examining the code, not from personal knowledge) some version of MSIE have a userAgent string that includes "MSIE xx;" and other versions have "MSIE (something)xx". So all that code is doing is finding where the beginning and end of "xx" is.

    It could have all been done much simpler using a regular expression, if anybody cares.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.


  •  

    Posting Permissions

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