views:

776

answers:

3

Hello

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.

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

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?

Thank you

+5  A: 

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"&gt;
    </noscript>
</head>

you can read more about meta refresh here

Hope this helps

EDIT: 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.

Darko Z
+1  A: 

The simple answer is to have the entire app load via JS. That way, the app would never show for someone who has JS enabled.

An alternative would be to start your page with an iframe, which loads to a JS-checking page. All the page does is redirect the user to the app's true URL via JS. Thus, if the user doesn't have JS, they won't get redirected (and you can inform them that they need JS with <noscript> tags). (I say to use an iframe so you don't give non-JS users an easy URL to get to the app with.)

Daniel Lew
A: 

The <noscript></noscript> would seem to work. I would make the default a small loader with an overlay, and if the client does not support javascript, the javascript would never hide the loader. And the content in the <noscript> tag would show with the overlay.

ohdeargod