function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Browser Detection in VF

I've got a stylesheet I only want to load if user is using IE.  What's the best way to detect browser in VF?  Do I just need to inject some javascript?  Or is there a way to do this natively?




You should be able to access the user agent from the controller as follows:


String userAgent = ApexPages.currentPage().getHeaders().get('USER-AGENT');


Then you could set a property so that the css inclusion is only rendered based on the contents of this.  


I try to avoid javascript where possible, though I find most of the time I can't :)