ruby 判断客户端浏览器类型代码



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


see: http://stackoverflow.com/questions/4707400/rails-browser-detection-methods
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值