#### 31.6.1 Selecting a CSS file at run time

CSS support is a mixed bag; a lot depends on exactly which browsers, and which versions of them, you need to support. You might need to autodetect the browser and choose from different CSS files at run time, using a macro instead of a fixed link, to reference JavaScript code that detects the type of browser in use and selects an appropriate CSS file. For example:

    [CSS]
    WriteCssLink=Yes
    CssBrowserDetect=<$SelectCSS1>

As an alternative:

    [CSS]
    WriteCssLink=No

    [Inserts]
    Head=<$SelectCSS1>

Provide the referenced macro:

    [SelectCSS1]
    ; Include here the JavaScript from m2hmacro.ini

Sample macro [$SelectCSS1] contains JavaScript to detect several popular browsers. This macro, and an alternate, [$SelectCSS2], are included in file m2hmacro.ini, in your DITA2Go distribution directory. You can copy m2hmacro.ini file to the project directory, or just copy the macro definition into the configuration file for your project; see §37.1.1.2 Understanding where you can define named macros. You can modify the macro definition as needed; consult a JavaScript reference for syntax.

Previous Topic: 31.6 Linking to alternate CSS files

Next Topic: 31.6.2 Changing CSS files in the middle of a document

Parent Topic: 31.6 Linking to alternate CSS files

Sibling Topics:

31.6.2 Changing CSS files in the middle of a document

31.6.3 Customizing the CSS link tag

31.6.4 Using an alternate CSS link tag for Netscape 4