Dave Burke : Freelance .NET Web Developer specializing in Online Communities

CSBlogs : Supporting browser-specific CSS stylesheets

I wanted more control on how my CSBlog page displays for Firefox and IE-based browsers so I added the ability to load a specific CSS file in Community Server based on the browser type.  So IE, Maxthon and other IE-variants will use style.css, Firefox (and Netscape) browsers will use a style_gecko.css stylesheet.

First I added a browsercaps area in the blog web.config.  That code is here.

Then added my own utilities class in a new CommunityServer.DBVT namespace containing the CheckIsGecko() method.**

public static bool CheckIsGecko()
{
 return "gecko" == HttpContext.Current.Request.Browser.Browser.ToLower() &&
  HttpContext.Current.Request.Browser.MajorVersion >= 1;
}


Then updated the Style.cs class in the CommunityServer.Blogs.Controls namespace.


if (Utilities.CheckIsGecko())
 writer.WriteLine(styleFormat,CSSPath(weblog.Theme,"style_gecko.css"),"screen");
else
 writer.WriteLine(styleFormat,CSSPath(weblog.Theme,"style.css"),"screen");


** I didn't plan having to concern myself this early on with writing mods in such a way so I don't lose them on future CS upgrades.  But it will be important to document and isolate code updates as much as possible.

 

Comments (0) | Post RSS RSS comment feed

Posted on 3/22/2005 4:36:00 PM by Dave Burke
Categories: Community Server
Tags: No tags for this post

Related posts

Comments are closed

This site was built with the Sueetie .NET Open Source Community Framework. Learn more about Sueetie at Sueetie.com.