ASP
  Home arrow ASP arrow Page 2 - Creating Dynamic Style Sheets Using ASP
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
ASP

Creating Dynamic Style Sheets Using ASP
By: Thomas Carpe
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 9
    2002-11-21

    Table of Contents:
  • Creating Dynamic Style Sheets Using ASP
  • Browser Detection
  • IE 6

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Creating Dynamic Style Sheets Using ASP - Browser Detection


    (Page 2 of 3 )

    It's pretty easy in fact, to combine this technique with browser detection, producing a style sheet that will work in any browser:

    'Detect Client Browser Environment
    Dim strUserAgent ' browser type capture
    Dim IE5Plus, IE55Plus, css2compatible ' general purpose capabilities
    Dim NS, NS4, NS6, IE, IE4, IE5, IE6, Opera, Opera5 ' Browser Boolean Constants
    Dim OtherBrowser ' obsolete browser flags

    strUserAgent = LCase(cstr(request.ServerVariables("HTTP_USER_AGENT")))

    'Explorer
    IE = FALSE
    IE4 = FALSE
    IE5 = FALSE
    IE6 = FALSE
    If InStr(strUserAgent, "MSIE") Then
    IE = TRUE
    End If
    If InStr(strUserAgent, "MSIE 4") Then
    IE4 = TRUE
    ElseIf InStr(strUserAgent, "MSIE 5") Then
    IE5 = TRUE
    ElseIf InStr(strUserAgent, "MSIE 6") Then
    IE6 = TRUE
    End If

    'Opera
    Opera = FALSE
    Opera5 = FALSE
    If InStr(strUserAgent, "Opera") Then
    Opera = TRUE
    End If
    If InStr(strUserAgent, "Opera 5") _
    Or InStr(strUserAgent, "Opera/5") Then
    Opera5 = TRUE
    End If

    'Netscape
    NS = FALSE
    NS4 = FALSE
    NS6 = FALSE
    If InStr(strUserAgent, "Netscape6") Then
    NS6 = TRUE
    ElseIf InStr(strUserAgent, "Mozilla/4") AND Not (IE OR Opera) Then
    NS4 = TRUE
    End If
    'This may not be 100% accurate; there are a lot of browsers based on the Mozilla core
    If NS6 OR NS4 OR (InStr(strUserAgent, "Mozilla") AND Not (IE OR Opera)) Then
    NS = TRUE
    End If

    'If the document looses the Loose DTD instead of Transitional or Strict
    'then set css2compatible to FALSE for IE6 instead
    If Opera5 Or IE6 Or NS6 Then
    css2compatible = TRUE
    Else
    css2compatible = FALSE
    End If

    OtherBrowser = FALSE
    If Not (IE OR NS4 OR NS6 OR Opera) Then
    OtherBrowser = TRUE
    End If
    If InStr(strUserAgent, "MSIE 5") _
    Or InStr(strUserAgent, "MSIE 6") Then
    IE5Plus = TRUE
    Else
    IE5Plus = FALSE
    End If


    Generating the CSS
    Now that we have tools to detect the type of browser, it is very simple to customize the output of the style sheet. We start by changing the ASP content type to that of a CSS style sheet. Then we include the browser detection code in BrowserDetect.asp. With these two preliminary steps complete, we just use simple IF...Then code to specify where and when a given style command should be part of our definition.

    <% Response.ContentType = "text/css" %>
    <!--#include file="BrowserDetect.asp"-->
    #SampleBox {
    <% If Not NS4 Then %>
    font-family: Tahoma, Arial, sans-serif;
    font-size: 10pt;
    <% Else %>
    fontfamily: Tahoma, Arial, sans-serif;
    fontsize: 10pt;
    <% End If %>
    <% If css2compatible Then %>
    /* in css2 standard the width of the box does not invlude its padding, borders, or margins */
    width: 230px;
    height: 80px;
    padding: 10px;
    <% Else %>
    /* in older browsers, padding in considered part of a box's width and height */
    width: 250px;
    height: 100px;
    padding: 10px;
    <% End If %>
    }


    The above code accounts for two circumstances in which you'd wnt to customize CSS output, but there could be many more. The first is that one corrects for improperly implemented style commands in Netscape 4, which doesn't use the hyphen in font commands as it should. The second accounts for a rather critical clarification of the way padding should be implemented that was not corrected until version 6 or IE and Netscape.

    More ASP Articles
    More By Thomas Carpe


     

    ASP ARTICLES

    - Central Scoreboard with Flash and ASP
    - Calorie Counter Using WAP and ASP
    - Creating PGP-Encrypted E-Mails Using ASP
    - Be My Guest in ASP
    - Session Replacement in ASP
    - Securing ASP Data Access Credentials Using t...
    - The Not So Ordinary Address Book
    - Adding and Displaying Data Easily via ASP an...
    - Sending Email From a Form in ASP
    - Adding Member Services in ASP
    - Removing Unconfirmed Members
    - Trapping HTTP 500.100 - Internal Server Error
    - So Many Rows, So Little Time! - Case Study
    - XDO: An XML Engine Class for Classic ASP
    - Credit Card Fraud Prevention Using ASP and C...







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway