admin管理员组文章数量:1425815
In my rails site, i require javascript on all the pages. If it is not enabled, every page will fail.
What I want to do is, if there is no javascript enabled, I want to redirect them to another static page - asking users to enable the javascript first. I want this to happen for all the pages. Is it possible ?
I have tried to put code in my application controller and checked but some how things are not getting into place.. Is there any standard solution to this in rails .. may be a helper or something ... ?
In my rails site, i require javascript on all the pages. If it is not enabled, every page will fail.
What I want to do is, if there is no javascript enabled, I want to redirect them to another static page - asking users to enable the javascript first. I want this to happen for all the pages. Is it possible ?
I have tried to put code in my application controller and checked but some how things are not getting into place.. Is there any standard solution to this in rails .. may be a helper or something ... ?
Share Improve this question asked Sep 1, 2010 at 9:07 AnandAnand 10.4k26 gold badges91 silver badges138 bronze badges4 Answers
Reset to default 7Just use the <noscript>
element to show a link: <noscript>Your browser does not support scripting. Please use the <a href="#">lite version</a></noscript>
. It's likely you'll have very few users without scripting, so it's not worth spending much time on these features.
As a NoScript user, I find these redirections to be extremely annoying. If I decide that, yes, I want to allow this site to use JavaScript, I simply want to click the “allow JavaScript” thingie in my browser, which will reload the current page. With redirections, I need another step.
What I do instead is to place some code like this at the top of the page:
<div class='warning' id='js-warning'>
Sorry, this page really requires JavaScript to be useful.
… maybe a little more text on why …
</div>
<script language='JavaScript'>$('js-warning').hide()</script>
One technique that I've used successfully is to have the first page that's accessed—typically a login form—write a session cookie using JavaScript when the page loads. Then have the controller that the form submits to check for the existence of that cookie. If it doesn't exist then you know that JavaScript is not available and you can take appropriate action.
Change url: ´NOSCRIPT.HTML´ to your taste.
<noscript>
<meta http-equiv="refresh" content="0;URL=NOSCRIPT.HTML" />
</noscript>
Note: this is not valid HTML, though for this specific feature request, this is the only awnser. I could tell people on how to do it properly, but sometimes proper is not an option when a client is breathing down your neck and a pragmatic low cost solution is required ;)
That said, progressive enhancement is the proper thing to do and showing a message to enable javascript is definatly a cleaner way of informing your visitors to .. well enable JavaScript.
本文标签: ruby on railsCheck if Javascript is available and redirect to another pageStack Overflow
版权声明:本文标题:ruby on rails - Check if Javascript is available and redirect to another page - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745407943a2657334.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论