Browser detection

  • Tags : user-agent, browser
  • Latest : 0.4.3
  • Last Updated: 07 January 2013
  • Grails version : 1.2.2 > *
  • Authors : Gennady Tsarik
7 votes

2% of Grails users

Dependency :
compile ":browser-detection:0.4.3"

Documentation

Summary

This plugin provides service and tag library for browser detection. You can know what is the browser, version, operating system and language specified in request headers.

Installation

grails install-plugin browser-detection

Description

This plugin provides service and tag library for browser detection. You can know what is the browser, version and operating system specified in request headers. The plugin is built on top of user-agent-utils library

To install:

grails install-plugin browser-detection

And then add code to your gsp's:

<browser:isMsie>Internet Explorer</browser:isMsie>

<browser:isSafari></browser:isSafari>

<browser:isChrome></browser:isChrome>

<browser:isFirefox></browser:isFirefox>

<browser:isOpera></browser:isOpera>

<browser:isiPhone></browser:isiPhone>

<browser:isiPad></browser:isiPad>

<browser:isWindows></browser:isWindows>

<browser:isMobile>Mobile phones or Android, iPhone, iPad, iPod, Blackberry, etc.</browser:isMobile>

<browser:isOther>browser is undefined or user-agent header is not set</browser:isOther>

You can use the following structure that emulates switch behavior:

<browser:choice>

<browser:isIE6></browser:isIE6>

<browser:isIE7></browser:isIE7>

<browser:otherwise></browser:otherwise>

</browser:choice>

Or the following:

<browser:isSafari versionGreater="5">
This text is rendered if Safari version is greater than 5.
For example, 5.0.1, 5.1
</browser:isSafari>

<browser:isFirefox version="3.*"> It works for all Firefox versions like 3.1, 3.6 and so on </browser:isFirefox>

<browser:isMsie versionLower="7">Internet Explorer 5.0, Internet Explorer 6.0</browser:isMsie>

At the moment wildcards are allowed only for version attribute. Be aware that 5.1 is greater than 5 and 5.0 equals to 5.

You can call methods isMsie, isSafari, isChrome and others with UserAgentIdentService service.

You can send suggestions to vare6gin(et)gmail.com