views:

95

answers:

4

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 ... ?

+5  A: 

Just 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.

Reinis I.
I want to redirect them to a page where I can show them clearly how to enable javascript for the site to work
lakshmanan
Most users with disabled javascript have locked-down browsers and don't have the permissions necessary to re-enable it.
Mark Thomas
Indeed, I don't think anyone just disables scripting by their own choosing. Either they're power users and use NoScript and hence don't need your instructions, or it's disabled for them by their administrators.
Reinis I.
A: 
John Topley
but if you disable JS afterwards the cookie will remain set:) i'd recommend making the cookie "expire" after a while, and recreate it with a new value. But i'd go with the noScript tag here, its more standardized and basically that's the purpose of its existence
Quamis
A: 

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.

BGerrissen
where should i put this code, in body or in head?
lakshmanan
I would put it in the head for neatness sake. But works anywhere in the document ;)
BGerrissen
When implementing this solution please keep in mind that search engines can interpret these meta tags and this can have serious consequenses on how your pages end up in google and other search engines.This page: http://www.franticfish.co.uk/blog/seo/103-google-experiments-2010 (search for 'How does Google treat 'meta refresh' redirects?') seems to suggest that google will interpret as a redirect. In this case the content of the NOSCRIPT.HTML page would end up in the index.
Marco Tolk
obviously, progressive enhancement is better than any of these solutions, however if this is for an application that doesn't need to be indexed by search engines, this will suffice.
BGerrissen
-1 for bad and invalid HTML.
RoToRa
+2  A: 

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>
Christopher Creutzig
Does `hide()` actually remove it from the DOM, or apply `display: none`? Because some people might browse with JS **on** but CSS **off**. I will concede that this is a very, very small corner case :)
detly
Be my guest to use some removing JavaScript code instead. I do worry about CSS being accessible (voice-reader-friendly etc.), but CSS switched off? Not for me, thanks.
Christopher Creutzig