Show Navigation


Grails Browser Detection Plugin

Owner: mathifonseca | 3.4.0 | Mar 14, 2018 | Package | Issues | Source | License: Apache-2.0

dependencies {
    compile 'org.grails.plugins:browser-detection:3.4.0'



Build Status

This plugin provides a service and tag library for browser detection. It parses User-Agent in order to identify client's browser, operating system, etc. It depends on user-agent-utils library from HaraldWalker. If you want to contribute, report issues or just check the code. You can find it at GitHub.

Here are some of the things that you can currently do with this plugin. All this operations can be used from GSPs or you can use the UserAgentIdentService anywhere in your code.

Using UserAgentIdentService:

class TestController {

    def userAgentIdentService
    def index() {
        if (userAgentIdentService.isMobile()) {
            println 'Hello mobile device!'
            if (userAgentIdentService.isWindowsPhone()) {
                println 'Wow! Does this still exist?'
        } else {
            println 'Hello desktop browser!'
            if (userAgentIdentService.isInternetExplorer()) {
                println 'Redirecting to Chrome download page...'


Detecting Browsers

<browser:isMsie> This is Internet Explorer </browser:isMsie>
<browser:isSafari> This is Safari </browser:isSafari>
<browser:isChrome> This is Chrome </browser:isChrome>
<browser:isFirefox> This is Firefox </browser:isFirefox>
<browser:isOpera> This is Opera </browser:isOpera>

Detecting Devices

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

Detecting Operative Systems

<browser:isWindows> This is Windows </browser:isWindows>

Other operations

You can use the following structure that emulates switch behavior:


Or the one below:

<browser:isSafari versionGreater="5">
	This text is rendered if Safari version is greater than 5.
	For example, 5.0.1, 5.1
<browser:isFirefox version="3.*">
	It works for all Firefox versions like 3.1, 3.6 and so on
<browser:isMsie versionLower="7">
	Internet Explorer 5.0, Internet Explorer 6.0

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.

All of these taglibs have their negative assert by starting with isNot. For example:

	This text is rendered if the browser IS NOT Safari.
	This text is rendered if the browser IS NOT Firefox.
	This text is rendered if the browser IS NOT Internet Explorer.
	This text is rendered if the browser IS NOT Chrome.