如何检测用户是否禁用了 javascript?
我正在与一位朋友讨论浏览器中未启用 javascript 的用户以及如何向他们显示您网站的“无 javascript”版本。
这可能吗?怎样才能做到?
想法?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
不要尝试构建单独的 JS 和非 JS 版本的网站。构建一个非 JS 版本,然后使用 JS 增强它。这使得重用代码变得更加容易,允许您使用对象/特征检测来进行整个堆栈,如果开发人员更新网站的一个分支而不是另一个分支,那么没有 JavaScript 的用户就不太可能被抛在后面。
Don't try to build separate JS and non-JS versions of the site. Build a non-JS version and then enhance it with JS. This makes it easier to reuse code, allows you to use object/feature detection for the entire stack, and makes it less likely that users without JavaScript will be left behind if developers update one branch of the site but not the other.
如果您指的是 javascript,请查找
HTML 标记。
If you mean javascript, look up the
<noscript>
HTML tag.如果您正在谈论 JavaScript 并希望为那些没有 JavaScript 的人提供网站的替代版本,只需为他们提供没有 JavaScript 的网站并将其放在页面顶部即可:
If you are talking about JavaScript and want an alternate version of your site for those without, simply give them site without and put this at the top of your page:
像这样:
仅当浏览器上没有启用脚本时才会执行元刷新(声明性重定向)。当然,noscript 标签只有具有 javascript 引擎的浏览器才能理解。如果你试图捕获根本没有 javascript 的浏览器(我不知道有多少),那么这是行不通的。
Like this:
The meta refresh (declarative redirect) only gets executed if there is no script enabled on the browser. Of course, the noscript tag is only understood by browsers that have a javascript engine. If you're trying to catch browsers that have NO javascript at all (I don't know of many) then this won't work.
我使用 JavaScript 和 CSS 的这种组合
如果您的唯一目的是告诉用户 JavaScript 不可用并且该网站将无法运行,那么它会很有用。
I use this combination of JavaScript and CSS
It's useful if your only aim is to tell the users that Javascript is not available and that the site will not work.
您可以使用该标签添加一些代码来记录/跟踪/警告您禁用 JavaScript 的用户。
You can put some code to log/track/alert you about users who have JavaScript disabled by using the tag.
与明显的 noscript 标记不同,您可以选择的另一个选项是使用 JavaScript 删除 cookie,然后测试该 cookie 并适当地传递内容。 javascript ver 与非重定向或跨度
只是想我会把它扔在那里..
Another option open to you rather than the obvious noscript tag is to use JavaScript to drop a cookie, and then test for that cookie and deliver content appropriately. javascript ver vs non redirect or span
just thought I'd throw that in there..