【发布时间】:2013-03-10 14:50:22
【问题描述】:
如果用户在其浏览器中启用了 javascript,我如何检查我的布局代码? 如果未启用 javascript,我想显示一个错误页面。例如。 404 或 500 错误页面。我如何使用 Rails 做到这一点?
【问题讨论】:
如果用户在其浏览器中启用了 javascript,我如何检查我的布局代码? 如果未启用 javascript,我想显示一个错误页面。例如。 404 或 500 错误页面。我如何使用 Rails 做到这一点?
【问题讨论】:
我不确定在 Rails 中检查 javascript 是否理想。如果你真的想这样做,我发现了这个:Check if Javascript is Enabled (Serverside) with Rails
但是,您可以只显示带有<noscript> 标签的消息,例如:
<noscript>YOU DON'T HAVE JAVASCRIPT AND THAT OFFENDS ME</noscript>
大多数浏览器默认启用 javascript,因此这是一个不常见的问题。如果您愿意,可以在<noscript> 中包含link_to,以便向他们展示如何像这样激活javascript:
<noscript>You don't have javascript enabled. Please follow this link for assistance in turning it on. <%= link_to "Turn on javascript", "http://www.enable-javascript.com" %>
编辑
我刚刚发现了这个。我还没有尝试过,但它看起来正是你要找的东西:Ruby on Rails, Javascript detection
<head>
<!-- title, scripts, css etc go here -->
<noscript>
<meta http-equiv="refresh" content="2;url=http://yoursite.com/nojswarning.html">
</noscript>
</head>
【讨论】: