Check if javascript and cookies are enabled in ruby ​​on rails?

I want to check if javascript and cookies are enabled or not when loading a page in Ruby on Rails. Therefore, if someone tries to open it, the website should show a message that it cannot continue further.

+4
source share
3 answers

You can use the <noscript> ... </noscript> . See here for more information.

+2
source

If you need this server side, you can set a cookie through javascript. If the rails cannot read it, then the user does not have cookies or javascript.

0
source

The <noscript> tag does not seem to work with script blockers such as chrome ScriptSafe. In this case, I found a workaround: create a warning message that is deleted in case javascript works well.

This is a warning message with id = "noscriptmessage":

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

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

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

Make sure the script message is found after the message (for example, if you put the script in the header before the warning message, this will not work).

0
source

Source: https://habr.com/ru/post/1443211/


All Articles