admin管理员组

文章数量:1421190

<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?

<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?

Share Improve this question edited May 3, 2012 at 13:30 THelper 15.6k6 gold badges67 silver badges106 bronze badges asked May 1, 2012 at 17:48 Ali BassamAli Bassam 9,98924 gold badges70 silver badges119 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

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).

<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.

本文标签: Checking if browser is javascript enabled or notStack Overflow