Omni Systems, Inc. Mif2Go User's Guide, Version 55

<< Prev | Next >>

> 22 Setting up CSS for HTML > 22.6 Linking to alternate CSS files > 22.6.1 Selecting a CSS file at run time

### 22.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 Mif2Go 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 §28.1.1.2 Understanding where you can define named macros. You can modify the macro definition as needed; consult a JavaScript reference for syntax.