How to block users to accessing Drupal website if javascript is not enabled? I checked many pages in Drupal Answers, which didn't have the answer of the following question:

Consider a case that I need javascript to be enabled for visual effects in drupal design.

How can I stop my website and show a message , if javascript is not enabled in user's browser?

Stop means to block the access of user to the website and showing a message like:

Please enable JS in your browser!

(I use Drupal 7.x)
It is not possible, not in the way you think of. Workflow is:


Server gets HTTP request.
Drupal process that request and returns HTML.
Browser runs JavaScript, or does not.


As you can see, server never knows if JS is there. If JS is on, you can send AJAX request, but if it's not, you can't do anything at this point.

You have three options:


Graceful degradation - this is what I would recommend. Use modules and write code that will simply not fail if JS is not there. It may look differently, that's OK, but should look good and work all right. I recommend these articles: Fault tolerance, Unobtrusive JavaScript
Use HTML &lt;noscript&gt; tag. It will not hide the rest of your site, but it will tell your users what is happening. This method can be used together with 1st one. Related Q&amp;A: How to Add noscript in head tag (Thanks Wtower for link)
Output a page with "Please enable JS in your browser!" message and immediately load real content with AJAX. That's the only way I can think of to make your site work like you want it to, but it is so wrong, on so many levels... Remember, some bots may be unable to index your page if you don't have JS enabled, your users with JS on would see message while waiting for real content anyway, and so on. And while Google can read JS-generated content now, Bing and other search engines apparently still cannot.