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 cann
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.
You coud use the <noscript> ... </noscript>
tag. For more information look here.
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).