2

How can I check in my layout code if the user has enabled javascript in his browser? If javascript is not enabled I want to show an error page. E.g. a 404 or a 500 error page. How can I do this with Rails?

1

1 Answer 1

8

I'm not sure if checking for javascript within Rails is ideal. I found this if you really do want to do it: Check if Javascript is Enabled (Serverside) with Rails

However, you can just show a message with <noscript> tag like:

<noscript>YOU DON'T HAVE JAVASCRIPT AND THAT OFFENDS ME</noscript>

Most browsers have javascript enabled by default so this is an uncommon problem. If you want you can include a link_to within the <noscript> in order to show them how to activate javascript like this:

<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" %>

EDIT

I just found this. I haven't tried it but it looks like exactly what you're looking for: 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>
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.