안녕하세요, 저는 모두 업계에서 레일스에서 브라우저 탐지를 위해 어떤 방법이 표준인지 궁금합니다. 브라우저를 결정하고 (X) HTML의 본문 요소에 클래스 또는 ID를 적용하는 데 도움이 될 수있는 보석, 라이브러리 또는 샘플 코드가 있습니까? 고마워, 나는 모두가 무엇을 사용하고 있는지 그리고 이것을 수행하는 허용 된 방법이 있는지 궁금해하고있다.레일 브라우저 감지 방법
우리는 user.agent를 가져 와서 해당 문자열을 구문 분석 할 수 있음을 알고 있지만 브라우저 감지를 수행하는 것이 허용되는지 여부는 확실하지 않습니다.
또한 여기서는 지형지 물 감지에 대해 논쟁하지 않으려 고합니다. StackOverflow에서 여러 답변을 읽었습니다. 내가 한 모든 질문은 사용자가 수행 한 작업입니다. 이 레일에 대해 이동하는 가장 좋은 방법 인 경우 여전히
[업데이트]
GitHub의에 faunzy 덕분에, 나는 종류의 레일에서 사용자 에이전트 확인에 대한 약간의 이해했습니다 그래서,하지만 확실하지 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
참고를 위해 고마워, 나는 내 자신을 창조하기 위해 그 도서관을 사용 해왔다. – alvincrespo
내가 궁금한데 ... 도서관의 버전에 무엇을 추가 했습니까? 소스 코드를 사용할 수 있습니까? –
링크가 작동하지 않습니다. : x –