I want to inform a user if javascript is disabled in the browser and tries to access my website. My information will be like: "Please enable javascript in your browser for better use of the website". So how to do this?
3 Answers
If informing your users to enable it is all you want to do, you don't need to depend on server-side code (in fact, I don't think you can). Just use a <noscript>
element:
<noscript><p>Please enable JavaScript in your browser for better use of the website.</p></noscript>

- 700,868
- 160
- 1,392
- 1,356
-
This is extremely dangerous for SEO. Google index this in all of your pages if its at the top – Assassinbeast May 17 '20 at 03:06
Well there's the tag for displaying html only without javascript, but if you want to control the CSS depending on it the best thing to do is to then specify .no-js before any CSS that's only for if JS is disabled, then as your first meaningful line of javascript remove that class from the body (and possibly add a .with-js class to apply js-only styles).
You can also have no default class but add one only with JS, it comes down to personal preference though you can/do get a slight flash of content intended for no javascript with the former before the body class is removed.

- 1,517
- 10
- 9
<noscript>
<div id="noscript-warning">Stack Overflow works best with JavaScript enabled<img src="http://pixel.quantserve.com/pixel/p-c1rF4kxgLUzNc.gif" alt="" class="dno"></div>
very easy u can do it in this way this is how stack overflow use to alert user if java script is dsabled

- 6,991
- 8
- 35
- 67
-
Do note, though, that it says "works best with JavaScript enabled", not "breaks and leaves you looking at a 'No JavaScript? Get lost!' page". – Jeffrey Hantin Jul 16 '10 at 06:50