BrowserServe Documentation MODx
BrowserServe is a MODx snippet that allows you to include resources such as CSS and JavaScript based on basic but flexible and easy to use user agent string matches. For example you can include a specific stylesheet if a visitors user agent is Internet Explorer or have a unique message displayed.
Note: This is an extremely early beta release.
Installation
Install via the MODx package manager. From the Admin area go to System > Package Management and search for BrowserServe.
Requirements
- MODx Revolution 2.0.0-RC-2 or later
- PHP5 or later
Usage examples
You can insert the snippet anywhere in a document for inserting CSS and JavaScript. If you plan to use a chunk or return the user agent string you should place it in the document where you want the output to appear.
Insert a stylesheet for IE7 browsers:
[[!BrowserServe? &userAgent=`MSIE 7` &insertCSS=`ie7.css`]]
Display a message (chunk) for IE6 users:
[[!BrowserServe? &userAgent=`MSIE 6` &tpl=`noie6-chunk`]]
Insert a JavaScript file for all non-Opera browsers:
[[!BrowserServe? &userAgent=`Opera` &matchType=`0` &insertJS=`non-opera-script.js`]]
Display the users raw user agent string:
[[!BrowserServe? &returnAgent=`1`]]
Insert JavaScript for Linux users:
[[!BrowserServe? &userAgent=`Linux` &insertJS=`linux-script.js`]]
Insert a stylesheet for all Opera, Firefox and Chrome users:
[[!BrowserServe? &userAgent=`Opera,Firefox,Chrome` &insertCSS=`stylesheet.css`]]
Insert stylesheets and scripts for all non-Windows users:
[[!BrowserServe? &userAgent=`Windows` &matchType=`0` &insertCSS=`stylesheet1.css,stylesheet2.css` & insertJS=`script1.js,script2.js`]]
Insert stylesheet and JavaScript for all Windows, Mac OS and Linux users:
[[!BrowserServe? &userAgent=`Windows,Mac OS,Linux` &insertCSS=`stylesheet.css` & insertJS=`script.js`]]
Properties
| Property | Description | Default |
| returnAgent | If true, will return the user agent string | 0 |
| matchType | If set to true, will include resources if a match is made. If set to false, will include when a match isn't made. | 1 |
| userAgent | A comma-separated list of string blocks used to detect browsers by matching the value in the user agent. | |
| insertCSS | A comma-separated list of CSS files to insert into the document head if a match is true. | |
| insertJS | A comma-separated list of JavaScript files to insert into the document head if a user agent match is found. | |
| insertBodyJS | The same as insertJS except JavaScript is added before the closing body tag. | |
| runSnippet | A comma-separated list of snippets to execute if a user agent match is found. NOTE: This isn't recommended. | |
| tpl | A chunk name to use and display if the correct matches are made. |
Placeholders
BrowserServe only uses one placeholder that can be used in chunks.
| Property | Description |
| [[+useragent]] | The visitors full user agent string. |
