Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browser detection for Rails
JavaScript Ruby
Tree: 2be7a0ff0e

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
doc
lib
test
.gitignore
.yardopts
Gemfile
History.txt
Manifest.txt
README.md
Rakefile
VERSION
browser_detect.gemspec
init.rb

README.md

Browser Detect

It's like a crystal ball for user agents.

Detect it.

Detects the client browser using the user agent string that was used to make the page request.

Browser Detect currently supports the following browsers and platforms:

Browsers:

  • ie
  • gecko
  • konqueror
  • opera
  • ipad
  • ipod
  • iphone
  • chrome
  • safari

Robots:

  • googlebot
  • msnbot
  • yahoo!

Operating Systems:

  • TODO

Install it:

Using Bundler, all you need to do is add the source to your Gemfile:

gem "browser_detect", :require => "browser_detect", :git => 'git://github.com/traction/browser_detect.git'

Then run:

bundle install

or, install it as a plugin:

script/plugin install git://github.com/traction/browser_detect.git

Wield it.

To check the type of browser, use browser_name @browser_name will return either 'ie', 'gecko', 'opera', 'konqueror', 'ipod', 'ipad', 'iphone', 'chrome', 'safari', 'googlebot', 'msnbot', 'yahoobot'

def index
    @browser_name = browser_name
end

To check if a particular browser made the request, use browser_name?(name) If the browser used is chrome, it will return True

def index
    @browser_type = browser_is?("chrome")
end

or in a view using ERB:

<%= browser_is?(:chrome) ? "secrets" : "buzz off" %>

Or choose from the following groupings:

  • mozilla
  • ie
  • webkit
  • robots
Something went wrong with that request. Please try again.