相关疑难解决方法(0)

Rails浏览器检测方法

嘿大家,我想知道行业中哪些方法是Rails中的浏览器检测标准?是否有某个宝石,库或示例代码可以帮助确定浏览器并将类或ID应用于(X)HTML的body元素?谢谢,我只是想知道每个人使用什么以及是否有可接受的方法来做到这一点?

我知道我们可以获取user.agent并解析该字符串,但我不确定这是否是一种可接受的浏览器检测方式.

另外,我不打算在这里讨论功能检测,我已经在StackOverflow上阅读了多个答案,我要求的就是你们所做的.

[UPDATE]

所以感谢GitHub上的faunzy,我对Rails中的用户代理进行了一些了解,但是仍然不确定这是否是在Rails 3中进行此操作的最佳方式.但这就是我所得到的远:

def users_browser
user_agent =  request.env['HTTP_USER_AGENT'].downcase 
@users_browser ||= begin
  if user_agent.index('msie') && !user_agent.index('opera') && !user_agent.index('webtv')
                'ie'+user_agent[user_agent.index('msie')+5].chr
    elsif user_agent.index('gecko/')
        'gecko'
    elsif user_agent.index('opera')
        'opera'
    elsif user_agent.index('konqueror')
        'konqueror'
    elsif user_agent.index('ipod')
        'ipod'
    elsif user_agent.index('ipad')
        'ipad'
    elsif user_agent.index('iphone')
        'iphone'
    elsif user_agent.index('chrome/')
        'chrome'
    elsif user_agent.index('applewebkit/')
        'safari'
    elsif user_agent.index('googlebot/')
        'googlebot'
    elsif user_agent.index('msnbot')
        'msnbot'
    elsif user_agent.index('yahoo! slurp')
        'yahoobot'
    #Everything thinks it's mozilla, so this goes last
    elsif user_agent.index('mozilla/')
        'gecko'
    else
        'unknown'
    end
    end

    return @users_browser
end
Run Code Online (Sandbox Code Playgroud)

ruby user-agent ruby-on-rails browser-detection

51
推荐指数
3
解决办法
3万
查看次数

用JavaScript检测iPad版本

是否可以在Web应用程序中检查iPad版本(1或2)?由于用户代理看起来相同(请参阅http://www.webtrends.com/Support/KnowledgeBase/SolutionDetail.aspx?Id=50140000000acbiAAA),因此浏览器的标准检查在此处不起作用.

我们可以检查JavaScript中仅在版本2中可用的功能(如陀螺仪)吗?

javascript ipad browser-feature-detection

12
推荐指数
3
解决办法
1万
查看次数

Rails 3:如何存储屏幕分辨率?

我想在用户登录时将用户的屏幕分辨率存储在数据库中.用户登录时如何检测并存储到数据库?

ruby screen-resolution ruby-on-rails-3

1
推荐指数
1
解决办法
1746
查看次数