Design and CSS styles
Version 7.x > Design and CSS styles > Conditional HTML tag Classes View modes: 
User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 11/19/2013 8:51:22 AM
   
Conditional HTML tag Classes
Where is the best place to add the following:
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en"> <!--<![endif]-->
I've attempted to add it into a HTML Tag Code webpart although it places the code after <html and before the closing >. So not ideal really. I've also attempted to simply set the class="" attribute with no success using that webpart.

So now I've modified the /CMSPages/PortalTemplate.aspx page and added the following:
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8" lang="en"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9" lang="en"> <![endif]-->
<!--[if gt IE 8]><!--> <html <%=XmlNamespace%> class="no-js" lang="en"> <!--<![endif]-->
And it seems to work but how do I get the XmlNamespace property to work with all the other conditions?

User avatar
Certified Developer 13
Certified Developer 13
kentico-jx2tech - 11/19/2013 9:47:36 AM
   
RE:Conditional HTML tag Classes
Maybe try detecting IE on the server and return the HTML Tag Code webpart value...
{% 
MyClass = "no-js";
if (BrowserInfo.IsIE) {
if (BrowserInfo.BrowserMajorVersion < 9) {
MyClass += " lt-ie9";
}
if (BrowserInfo.BrowserMajorVersion < 8) {
MyClass += " lt-ie8";
}
if (BrowserInfo.BrowserMajorVersion < 7) {
MyClass += " lt-ie7";
}
}
return "class=\"" + MyClass + "\" lang=\"" + CurrentPageInfo.DocumentCulture + "\"";
%}
This can save a few bytes and not penalize other browsers for IE ;)

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 11/19/2013 1:42:28 PM
   
RE:Conditional HTML tag Classes
Nice! Worked like a charm!

User avatar
Certified Developer 13
Certified Developer 13
kentico-jx2tech - 11/19/2013 2:31:29 PM
   
RE:Conditional HTML tag Classes

great. here is little improvement to spare IE9+ from all the extra ifs.
{% 
MyClass = "no-js";
if (BrowserInfo.IsIE && BrowserInfo.BrowserMajorVersion < 9) {
MyClass += " lt-ie9";
if (BrowserInfo.BrowserMajorVersion < 8) {
MyClass += " lt-ie8";
}
if (BrowserInfo.BrowserMajorVersion < 7) {
MyClass += " lt-ie7";
}
}
return "class=\"" + MyClass + "\" lang=\"" + CurrentPageInfo.DocumentCulture + "\"";
%}