Ruby on Rails,Javascript检测 [英] Ruby on Rails, Javascript detection

查看:116
本文介绍了Ruby on Rails,Javascript检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个Web应用程序,它使用Rails内置帮助程序函数向站点添加ajax功能。我不希望用户能够在没有JS的情况下使用该应用程序,因为它无法正常运行。

I am creating a web app that uses Rails built-in helper functions to add ajax functionality to the site. I do not want the user to be able to use the app without JS as it will not function properly.

我需要能够阻止这种情况。如何在没有JS的情况下阻止用户加载任何页面?

I need to be able to prevent this. How can I go about stopping the user from loading any of my pages without JS?

我试图在布局中使用标签。这会检测到JS的缺失但仍会呈现视图。将脚本标记放在yield之后会阻止任何视图呈现。

I have tried to use a tag in my layout. This detects the absence of JS but still renders the views. Putting the script tag around the yield prevents any view from being rendered.

有关如何执行此操作的任何想法吗?

Any ideas on how to do this?

推荐答案

您可以在 head 元素中使用 noscript 块元刷新标签。示例:

You can have a noscript block in the head element with a meta refresh tag in it. Example:

<head>
    <!-- title, scripts, css etc go here -->
    <noscript>
        <meta http-equiv="refresh" content="2;url=http://yoursite.com/nojswarning.html">
    </noscript>
</head>

您可以阅读有关元刷新的更多信息这里

you can read more about meta refresh here

希望这会有所帮助

编辑:为了澄清,只有在为用户关闭JavaScript时, noscript 标记才会运行。因此,在这种情况下,如果关闭JS,用户将被重定向到 http://yoursite.com/nojswarning.html 。当然,您可以将其更改为您想要的任何网站上的任何页面。

To clarify, the noscript tag runs only if JavaScript is turned off for the user. So in this case if the JS is turned off the user will be redirected to http://yoursite.com/nojswarning.html. of course you can change this to be any page on any site you want.

这篇关于Ruby on Rails,Javascript检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆