How to detect if JavaScript is disabled?

后端 未结 30 3436
暗喜
暗喜 2020-11-21 07:37

There was a post this morning asking about how many people disable JavaScript. Then I began to wonder what techniques might be used to determine if the user has it disabled.

30条回答
  •  情歌与酒
    2020-11-21 08:10

    You don't detect whether the user has javascript disabled (server side or client). Instead, you assume that javascript is disabled and build your webpage with javascript disabled. This obviates the need for noscript, which you should avoid using anyway because it doesn't work quite right and is unnecessary.

    For example, just build your site to say

    This website doesn't work without JS

    Then, your script will simply do document.getElementById('nojs').style.display = 'none'; and go about its normal JS business.

提交回复
热议问题