How to detect if a user had javascript disabled?

2020-07-18 23:14发布

I was talking with a friend about users who do not have javascript enabled in their browser and what could be done to show them a "no-javascript" version of your website.

Is it possible and how can it be done?

Thoughts?

7条回答
一夜七次
2楼-- · 2020-07-19 00:00

I use this combination of JavaScript and CSS

<html>
<style type="text/css">
    .js-on
    {
        display: none;
    }
    .js-off
    {
        background: red;
        color: White;
    }
 </style>
 <div id='jsdetect' class='js-off'><b>Javascript is OFF</b></div>
 <script type="text/javascript">
    document.getElementById('jsdetect').className = 'js-on';
 </script>

</html>

It's useful if your only aim is to tell the users that Javascript is not available and that the site will not work.

查看更多
登录 后发表回答