检查浏览器名称和版本的简单方法

发布于 2024-09-16 05:45:45 字数 601 浏览 2 评论 0原文

有没有非常简单的方法来了解浏览器调用了控制器的操作。

我想要我的控制器的代码,如下所示:

if mighty_lib.browser.name == "Safari"
   if mighty_lib.browser.version >= 5
       # Glad to see you, Safari 5, there is a stunning, interactive page for you.
   elsif mighty_lib.browser.version >= 4
       # Glad to see you, Safari 4, there is a less advanced page for you.
   end
if mighty_lib.browser.name == "Firefox"
   # Quick brown fox jumps over the lazy dog
elsif mighty_lib.browser.name == "IE"
   # Oh, my god ... Change your browser ! There is a "Jurassic Park" movie for you
end

Is there any really easy way to get to know, what browser has called controller's action.

I would like to have a code for my controller, like this:

if mighty_lib.browser.name == "Safari"
   if mighty_lib.browser.version >= 5
       # Glad to see you, Safari 5, there is a stunning, interactive page for you.
   elsif mighty_lib.browser.version >= 4
       # Glad to see you, Safari 4, there is a less advanced page for you.
   end
if mighty_lib.browser.name == "Firefox"
   # Quick brown fox jumps over the lazy dog
elsif mighty_lib.browser.name == "IE"
   # Oh, my god ... Change your browser ! There is a "Jurassic Park" movie for you
end

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

勿忘初心 2024-09-23 05:45:45

我建议服务器不是处理不同浏览器要求的最佳位置 - 通常,使用智能 css 和(不引人注目的)javascript 根据浏览器的特定功能在客户端打开和关闭功能是更好的方法客户端而不是修复特定版本。

I would suggest that the server is not the best place to handle different browser requirements - it is generally a much better approach to use smart css and (unobtrusive) javascript to turn features on and off on the client-side according to the specific capabilities of the client as opposed to fixing on specific versions.

书信已泛黄 2024-09-23 05:45:45

您可以使用这个旧插件,或者编写一些使用request.env["的原始代码HTTP_USER_AGENT"]。另外,请查看 Ruby 论坛 上的评论。

You may use this old plugin, or write some raw code that uses request.env["HTTP_USER_AGENT"]. Also, take a look at this comment at Ruby forums.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文