SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Good way to detect IE6 but not IE7 using object detection?

    I'm using javascript to fix a couple of IE6's horrible CSS deficiencies. Since with what I'm doing I'm already using javascript, it would be nice to just add a function to my current script to deal with this fix and not add a whole new bit in conditional comments. Besides, I'm curious what you think.

    So far I've found most people seem to be liking doing
    Code:
    if (!window.XMLHttpRequest) {//IE6- stuff;}
    or perhaps a more bullet-proof (or redundant?) version:
    Code:
    if (document.all && !window.opera && !window.XMLHttpRequest) {//IE6 stuff}
    But some people seem to think this isn't that great because IE7 users can disable XMLHttpRequest in the program's options. There's also this:
    Code:
    if (typeof document.addEventListener != 'function') {//IE6 stuff}
    or I also found someone blogging about this:
    Code:
    if (typeof document.body.style.maxHeight == "undefined")  {//IE6 stuff}

    What say you?

  2. #2
    CTO htmlguy's Avatar
    Join Date
    Feb 2005
    Location
    North Carolina
    Posts
    420
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    <!--[if IE 6]>
    Special instructions for IE 6 here
    <![endif]-->

    or for all IE versions

    <1--[if IE]>
    Special instructions for all of IE versions
    <![endif]-->


    I use this and it works wonderfully. The XMLHTTPRequestObject stuff is mainly for AJAX applications (for the most part).
    HTMLGuy

  3. #3
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    htmlguy has good advice

    here's some more:

    Code:
    /*@cc_on
    @if (@_jscript_version <= 5.6)
      // js code for IE6 or down
    @else @*/
      // js code for IE7 and non-IE browsers
    /*@end @*/
    [edit]

    ...and not add a whole new bit in conditional comments.
    Oops! I should have read your post closer

  4. #4
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Well, I meant HTML conditional comments actually... I'd never even heard of conditional compilation!

    It seems pretty cool, though there doesn't seem to be an awful lot on it online, especially when compared to HTML conditional comments. Is there any particular reason why they shouldn't be used or is it just that normally people do object detection because they want to use it at that point?

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    You use object detection when you are going to actually use the object that you are testing for. Testing for objects other than the one you are going to use is not correct usage of the tests - they should be testing for the object that they are actually going to use or where IE (or some versions of IE) use a non-standard call to the object there are the Javascript conditional statements that few people seem to have hard of that are the way that it should be done. Since IE is the only browser that runs jscript rather than javascript just testing if jscript is supported is sufficient to distinguish IE from other browsers. Testing the jscript version should work for distinguishing IE7 from earlier but is less accurate for identifying earlier IE versions where the jscript version can differ depending on which version of Windows and what patches/service packs you have installed even for the same version of IE.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  6. #6
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    That's interesting. However, since it's a fair few lines of JS that I need to give IE6- only, I decided to do this in my main external script in the <head>:
    Code:
    //Some JS for everyone
    if (typeof(ieStuff) != 'undefined') ieStuff();
    // More JS for everyone
    And later on in the <head>:
    HTML Code:
    <!--[if lte IE 6]><script type="text/javascript" src="js/ie.js"></script><![endif]-->
    which is the file containing ieStuff plus another ie-only function. I think this seems quite reasonable though if you see any problems with it by all means tell me please.

  7. #7
    SitePoint Zealot
    Join Date
    Jul 2006
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What does the lte in the conditional comment mean? I thought it was an acronym for less than or equal to? Does that mean you'd be fixing problems incorrectly in IE 5.5 and IE 5?

    Dave

  8. #8
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Yes, it's less than or equal. I'm fixing for things that IE7 implemented by that IE5 and 6 didn't. 5 and 6 have more or less similar implementations of CSS, so I'll apply my fixes to them too. If they mess IE5.x at all it's not much of a problem, since they can't mess it up more than it is already and practically nobody uses those anyway.


Bookmarks

Posting Permissions

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