Coder Social home page Coder Social logo

browser_detect's Introduction

Browser Detect

It's like a crystal ball for user agents.

Browser Detect identifies the client browser using the user agent string that was supplied in the page request. Browser Detect searches the user agent string for any string you provide, and it also supports some special groupings and shortcuts:

  • ie (Any version of IE, excluding browsers like Opera and WebTV that identify themselves as IE)
  • ie{integer} (A specific major version of IE โ€” "ie6", "ie7", "ie8", etc.)
  • robot (Google bot, MSN bot, Yahoo! bot)
  • ios (iPhone, iPod, iPad)
  • webkit (Any WebKit based browser)
  • mobile (Any modern mobile browser โ€” iOS, Android, Palm webOS)

Install it.

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

gem "browser_detect"

Then run:

bundle install

or, install it as a plugin using Rails 2:

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

Wield it.

To check if a particular browser made the request, use browser_is?(name)

def index if browser_is?("chrome") # load some chrome-specific content end end

or in a view:

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

Don't forget you can use the special groupings listed above to target IE, robots, iOS, etc.

<%= stylesheet_link_tag "ugly_styles" if browser_is?('ie') %> <%= stylesheet_link_tag "even_uglier_styles" if browser_is?('ie6') %> <%= render "seo_spam_content" if browser_is?('robot') %>

There's also a convenience method browser_is_mobile? which is just a shortcut to browser_is?('mobile')

def index if browser_is_mobile? # redirect to the mobile site end end

For WebKit-based browsers, you can also check the WebKit version using browser_webkit_version. This can be useful for determining what rendering capabilities the browser has. For instance, early versions of Mobile WebKit crash intermittently when you use multiple faces or weights of web fonts. So you might prevent your web fonts from rendering on old WebKit versions:

<%= stylesheet_link_tag "fonts" unless (browser_is?('ios') and browser_webkit_version < 532) %>

Documentation

See http://rdoc.info/github/traction/browser_detect/master/frames

Contribute!

Additions to the text fixtures (list of user agent strings for testing) are always welcome, as are new definitions of browser groupings. Please fork and submit a pull request!

Authors

Originally based on work by rlivsey. Current contributors:

browser_detect's People

Contributors

armandocanals avatar eric1234 avatar faun avatar rlivsey avatar stopdropandrew avatar tmlee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

browser_detect's Issues

error when integrating with omniauth

.../lib/google_helper.rb:41:in `class:GoogleHelper': uninitialized constant GoogleHelper::OAuth (NameError)

I don't know where exactly is the error, but when I remove the gem from the Gemfile everything works fine

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.