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
<noscript>You need to enabled JavaScript to use this site.</noscript>
<noscript>You need to enabled JavaScript to use this site.</noscript>
But it doesn't really do anything no matter where I put it...
8 Replies
Matvey
Matvey2y ago
If your JS code runs, then JS is enabled, lol
JulieCezar
JulieCezarOP2y ago
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
Valhalaar
Valhalaar2y ago
This is what <noscript /> is for
Valhalaar
Valhalaar2y ago
: 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.
JulieCezar
JulieCezarOP2y ago
Yea, I knew about that however it seems I was using it wrong
JulieCezar
JulieCezarOP2y ago
My solution was adding the <noscript> tag in _app.tsx like so:
JulieCezar
JulieCezarOP2y ago
Then if I don't have JS enabled
JulieCezar
JulieCezarOP2y ago
Want results from more Discord servers?
Add your server