Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking if browser is javascript enabled or not

<noscript>
    <div>
        You must enable javascript to continue.
    </div>
</noscript>

Ok this makes sense, but still, the contents after this element will be shown, of course in a bad way, but what I am looking for is this:

If javascript is NOT enabled, I want to show this alert message, and NOTHING ELSE, I don't want to give advice "It's better if you enabled Javascript", I want to FORCE, "You MUST ENABLED so you can Continue!", I don't wanna give access to my website if javascript is not enbaled, how can I do that?

like image 829
Ali Bassam Avatar asked Dec 20 '22 22:12

Ali Bassam


2 Answers

Add a No-Javascript CSS class that hides everything else using CSS, and use Javascript to remove the class immediately (using an inline <script> block in that element).

like image 55
SLaks Avatar answered Jan 02 '23 22:01

SLaks


<noscript>
    <div style='position:fixed;left:0;top:0;width:100%;height:100%;background:#f55;z-index=1000">
        You must enable javascript to continue.
    </div>
</noscript>

Also, your question wanted to throw an alert.. Which is JavaScript. You basically asked "how can I execute JS when JS is disabled?". But this HTML alone will do the trick.

like image 28
DanRedux Avatar answered Jan 02 '23 23:01

DanRedux