How to check if user has enabled JS on page?
In NextJs / React how can I check if the user has enabled JS and display some kind of message or maybe even hide the whole site until it's enabled?
I tried
But it doesn't really do anything no matter where I put it...
8 Replies
If your JS code runs, then JS is enabled, lol
Yes, but I tried disabling JS on my site and it doesn't work (I mean of course it doesn't) but I would like to display a notification to the user that they should enable JS to be able to use my site.
Because then nothing happens and there is no clear indication whyy
This is what
<noscript />
is for: The Noscript element - HTML: HyperText Markup Language | MDN
The HTML element defines a section of HTML to be inserted if a script type on the page is unsupported or if scripting is currently turned off in the browser.
Yea, I knew about that however it seems I was using it wrong
My solution was adding the <noscript> tag in _app.tsx like so:
Then if I don't have JS enabled