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"
| SitePoint Sponsor |




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"


Programming Group Advisor
Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
Car is to Carpet as Java is to JavaScript




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 )


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




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.


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




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
Notice that there is already a css file.Code:if (mydiv.chars<300) {css code}


Programming Group Advisor
Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
Car is to Carpet as Java is to JavaScript




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)


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




I change the css I had but
worked at my firefox but not at my IE6 (I havent newest IECode:$('content_text').setStyle("vertical-align","middle");)
This worked at IE6 (maybe I do some error...)
Code:$('content_text').setStyle("position","relative"); $('content_text').setStyle("top","35%");


Programming Group Advisor
Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
Car is to Carpet as Java is to JavaScript

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.






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




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
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