SitePoint Sponsor

User Tag List

Results 1 to 20 of 20

Thread: detect IE6

  1. #1
    SitePoint Guru
    Join Date
    Mar 2006
    Posts
    701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    detect IE6

    How can I detect that user use IE7 or IE6.
    I made a google search but I was confused.
    For example does this link works ok for IE7 or IE6?
    Meaning that navigator.appName returns "Microsoft Internet Explorer"

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,687
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by dimis283 View Post
    How can I detect that user use IE7 or IE6.
    Typically by using object detection that relates to the problem you're trying to solve.

    What's the problem?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Guru
    Join Date
    Mar 2006
    Posts
    701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I want to use javascript to set some css if browser is IE6 and 7.
    Till now I set it if browser is IE.
    Also this site use moo tools so it has built in functions detecting the browsers (I did not use mootools )

  4. #4
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,687
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by dimis283 View Post
    I want to use javascript to set some css if browser is IE6 and 7.
    The best way to do that is without JavaScript.

    Using HTML conditional comments you can guarantee that it will work even if javascript is disabled.

    Code:
    <!--[if (gte IE 6)&(lte IE 7)]>
    <link type="text/css" rel="stylesheet" href="ie6-7.css">
    <![endif]-->
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  5. #5
    SitePoint Guru
    Join Date
    Mar 2006
    Posts
    701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The first problem is that I want the text of my "text div" to be in the middle of this div if it is "little" for example below 300 characters,so I want some css for IE6,7.
    Look this.

  6. #6
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,687
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    Why do IE6 and IE7 exclusively require the additional CSS codes? Because they need fixing in some way that IE8 or IE9 don't require?

    If that's the case, there are CSS specific techniques that easily achieve that without the complexities of scripting.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  7. #7
    SitePoint Guru
    Join Date
    Mar 2006
    Posts
    701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    For sure.
    But I need to know if text has bellow 300 (for example) characters ans so to give the new css.
    Can I do it with out javascript?
    How can I use plain css to find the characters or to give instructions like
    Code:
    if (mydiv.chars<300) {css code}
    Notice that there is already a css file.

  8. #8
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,687
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by dimis283 View Post
    For sure.
    But I need to know if text has bellow 300 (for example) characters ans so to give the new css.
    Can I do it with out javascript?
    How can I use plain css to find the characters or to give instructions like
    Code:
    if (mydiv.chars<300) {css code}
    Notice that there is already a css file.
    Why is IE6 and IE7 receiving the special treatment, while IE8 and IE9 are not?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  9. #9
    SitePoint Guru
    Join Date
    Mar 2006
    Posts
    701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I am a newbie at css.
    This was the suggestion at css forum.
    Maybe IE6 is too old for some css...as I notice for an error that gave me with that code...
    (My IE6 give an error for display:table-cell at javascript code)

  10. #10
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,687
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    Let me ask this another way.

    Please show us HTML/CSS code that have which works fine in IE8/IE9, but doesn't work as expected in IE6/IE7
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  11. #11
    SitePoint Guru
    Join Date
    Mar 2006
    Posts
    701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I change the css I had but
    Code:
    $('content_text').setStyle("vertical-align","middle");
    worked at my firefox but not at my IE6 (I havent newest IE )
    This worked at IE6 (maybe I do some error...)
    Code:
    $('content_text').setStyle("position","relative");
    $('content_text').setStyle("top","35%");

  12. #12
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,687
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by dimis283 View Post
    I change the css I had but
    Code:
    $('content_text').setStyle("vertical-align","middle");
    worked at my firefox but not at my IE6 (I havent newest IE )
    This worked at IE6 (maybe I do some error...)
    Code:
    $('content_text').setStyle("position","relative");
    $('content_text').setStyle("top","35%");
    What is the HTML we would need to use with that experience the problem?

    We cannot develop a working solution if we cannot experience the problem.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  13. #13
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,023
    Mentioned
    63 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dimis283 View Post
    How can I detect that user use IE7 or IE6.
    I made a google search but I was confused.
    For example does this link works ok for IE7 or IE6?
    Meaning that navigator.appName returns "Microsoft Internet Explorer"
    Test for functionality, not for browser version. The IE family has the If IE tags for use with HTML and CSS, but in javascript it is best to check to see if an object exists before attempting to use it.

    By testing for functionality you get a bit of future proofing, but also you don't need to worry as much about things breaking in other browsers.

  14. #14
    SitePoint Guru
    Join Date
    Mar 2006
    Posts
    701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Michael Morris View Post
    Test for functionality, not for browser version. The IE family has the If IE tags for use with HTML and CSS, but in javascript it is best to check to see if an object exists before attempting to use it.

    By testing for functionality you get a bit of future proofing, but also you don't need to worry as much about things breaking in other browsers.
    You are right but also at my situation for example the code
    Code:
    $('content_text').setStyle("display","table-cell");
    give an error at my IE7,IE6.

  15. #15
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,687
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by dimis283 View Post
    You are right but also at my situation for example the code
    Code:
    $('content_text').setStyle("display","table-cell");
    give an error at my IE7,IE6.
    Then use object detection as we have all been saying, to determine whether the web browser is capable of supporting such techniques.

    jQuery makes this easy. It provides useful support for object detection. Checking for box model support would be appropriate here.

    Code javascript:
    if ($.support.boxModel) {
        $('content_text').setStyle("display","table-cell");
    } else {
        // IE6 and IE7 will run the code in this "else" section
        // ...
    }

    What would you have the IE6/IE7 browsers do instead?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  16. #16
    SitePoint Guru
    Join Date
    Mar 2006
    Posts
    701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I understand but also this site use mootools (We make a few changes).
    Is there a way to do this with mootools (or a more generall way)?

  17. #17
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,687
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by dimis283 View Post
    I understand but also this site use mootools (We make a few changes).
    Is there a way to do this with mootools (or a more generall way)?
    Sure thing. You can a 1 pixel div with 1 pixel of left padding, and check if its offsetWidth is equal to 2. If it is, then you know the browser has proper box model support.

    That's the precise technique used by jQuery to check for box model support.

    Code javascript:
    // Figure out if the W3C box model works as expected
    // document.body must exist before we can do this
    jQuery(function() {
    	var div = document.createElement("div");
    	div.style.width = div.style.paddingLeft = "1px";
    	document.body.appendChild( div );
    	jQuery.boxModel = jQuery.support.boxModel = div.offsetWidth === 2;
    	document.body.removeChild( div ).style.display = 'none';
     
    	div = null;
    });

    Wrapping that in the MooTools wrapper without the jQuery stuff, and adding a few explanitory comments, we get this MooTools type of code:

    Code javascript:
    window.addEvent('domready', function() {
        function hasBoxModelSupport() {
            // Figure out if the W3C box model works as expected
            // document.body must exist before we can do this
     
            // Setup
            var isSupported = false;
            var div = document.createElement("div");
     
            // Test
            div.style.width = '1px';
            div.style.paddingLeft = '1px';
            document.body.appendChild(div);
            isSupported = (div.offsetWidth === 2);
     
            // Cleanup
            document.body.removeChild(div).style.display = 'none';
            div = null;
     
            return isSupported;
        });
     
        if (hasBoxModelSupport()) {
            // yay, box model support
        } else {
            // boo, IE6 or IE7
        }
    });
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  18. #18
    SitePoint Guru
    Join Date
    Mar 2006
    Posts
    701
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you.
    I fix it and now I do not use any browser detection.

  19. #19
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,687
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by dimis283 View Post
    Thank you.
    I fix it and now I do not use any browser detection.
    Well done. I feel sorry for all those people checking the first digit of the browser version number. They'll be okay with IE9, but when it goes to IE10 they're going to have real trouble.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  20. #20
    SitePoint Member PaulPov's Avatar
    Join Date
    Dec 2011
    Location
    Saint-Petersburg, Russia
    Posts
    12
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I truly believe we all should stop supporting IE6.
    It was made 10 years ago and the web has gone far.
    In my company - <snip/> I insist we don't provide IE6-optimized sites anymore.
    It's just not efficient from the business point of view to spend time optimizing a contemporary site for IE6.
    I prefer coming to the client's office and making them install a modern browser )
    Last edited by Mittineague; Dec 6, 2011 at 18:48. Reason: removing unnecessary link


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
  •