Detect MATLAB Help Browser
matlab
Solution
The capabilities of the MATLAB help browser differ greatly, not only between different MATLAB versions, but also between different operating systems and even between different architectures (the recent 64bit versions often have a particularly bad browser).
We're using the user agent to deliver MATLAB-specific web pages. Here's a list of some of them:
R2010b/R2011b, 32bit, WinXP:
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20060705
R2010b/R2011b, 32bit, Win7:
Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.8) Gecko/20060705
R2010b, 64bit, Win7:
Mozilla/5.0 (Java 1.6.0_17; Windows 7 6.1 amd64; de_DE) ICEbrowser/v6_0_2
R2011b, 64bit, Win7:
Mozilla/5.0 (Java 1.6.0_17; Windows 7 6.1 amd64; de_DE) ICEbrowser/v6_0_2
R2012a, 32bit, Win7:
Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2) Gecko
R2012a, 32bit, WinXP:
Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2) Gecko
R2012a, 64bit, Win7:
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Win64; x64; Trident/4.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; Tablet PC 2.0)
R2012b, 32bit, Win7:
Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2) Gecko
R2012b, 64bit, Win7:
Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.1; Win64; x64; Trident/4.0; .NET CLR 2.0.50727; SLCC2; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; .NET4.0C; .NET4.0E; Tablet PC 2.0)
R2010b, 32bit, Linux:
Mozilla/5.0 (Java 1.6.0_17; Linux 2.6.32-33-generic i386; en_US) ICEbrowser/v6_0_2
Note that you cannot simply do a string comparison against these, since some parts of the strings change depending on the client machine (e.g. the language code).
Also note that other capabilities besides rendering HTML and CSS differ greatly. In particular, support for JavaScript and HTTP authentication.
Problem
I'd like to create some HTML documentation for a large MATLAB application, to be viewed mainly within the MATLAB Help Browser, in any version of MATLAB from 11b on. This would have some custom CSS (but nothing very complicated). However, I'd also like the same documentation to be viewable within other browsers. I care about Chrome and IE9 and 10, although support for other browsers would be welcome. I'd like the documentation to - Look essentially the same across all the browsers including the MATLAB Help Browser, but - In a few ways look different when presented in the MATLAB Help Browser - in particular, I want `matlab:` links to be displayed and behave differently, as they are not supported outside the MATLAB Help Browser. Question 1: I'm running into difficulty even with 1, as despite the simplicity of my CSS the MATLAB Help Browser seems unpredictable in what parts of CSS it supports, and it seems to vary a great deal across MATLAB versions. I'm guessing that it's not documented at all. Does anyone have any experience/tips about using CSS in the MATLAB Help Browser? Question 2: I was hoping to be able to auto-detect somehow whether the `matlab:` protocol was supported in the viewing browser, but it seems from browsing other StackOverflow answers that this is not possible. Given that I need to support Chrome, it's not even possible to try following a `matlab:` link and detect if it fails, as apparently Chrome fails silently. Boo. So my next thought is to use JavaScript to detect the UserAgent of the browser. MATLAB 11b reports itself as Mozilla4.0 with `ICEbrowser`, whereas 13a gives Mozilla4.0 with `Trident6`. I'm not entirely sure what these are - I'm guessing they're third-party Java-based browser components that behave like Mozilla, and MathWorks have changed the component between 11b and 13a. If I detect the UserAgent and assume that anything containing the strings `ICEBrowser` or `Trident`, is that likely to be sufficient to distinguish the MATLAB Help Browser for most purposes? Obviously I'll have to keep up to date with UserAgent strings for post-13a releases. Thanks for your suggestions!