5

I want to check whether javascript and cookies are enabled or not on page load in Ruby on Rails. So if anyone tries to open it, website should display a message that he cannot proceed further.

1

3 Answers 3

3

You coud use the <noscript> ... </noscript> tag. For more information look here.

Sign up to request clarification or add additional context in comments.

2 Comments

Is there anyway to check it in application controller?
No not at all. As you have to load a page first.
0

If you need to know this server side, you can set a cookie through javascript. If rails can't read it, than the user doesn't have cookies or javascript enabled.

Comments

0

The <noscript> tag does not seem to work with script blockers like chrome ScriptSafe. For this case I have found a workaround: create an alert message that is removed, in case javascript works well.

This is the alert message with id="noscriptmessage":

<div id="noscriptmessage" style="color:red">
   This site requires javascript enabled!
</div>

And the following script will remove the message, if javascript is enabled and not blocked:

<script>
document.getElementById("noscriptmessage").innerHTML="";
</script>

Make sure that the script is found after the message (e.g., if you place the script in the header before the alert message, it will not work).

1 Comment

Sorry, I had missed the hint that this question was duplicate: see: link. There user "bobince" has described the same solution. You might want to check out that page, together with a ton of other possible solutions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.