如何处理在 AngularJS 中禁用 JavaScript
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22256371/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to handle JavaScript being disabled in AngularJS
提问by BrightIntelDusk
AngularJS is dependent upon JavaScript being enabled. This means that if someone visits an application or website built in AngularJS it will not render properly.
AngularJS 依赖于启用的 JavaScript。这意味着如果有人访问用 AngularJS 构建的应用程序或网站,它将无法正确呈现。
What are common conventions used to handle visitors with JavaScript disabled when using AngularJS?
使用 AngularJS 时,用于处理禁用 JavaScript 的访问者的常见约定是什么?
Please explain why this is the case?
请解释为什么会这样?
Included in the problem is the case of handling angular JS directives and {{data_bindings}}. So that the data does not show when the page cannot render the page.
问题包括处理 Angular JS 指令和 {{data_bindings}} 的情况。这样当页面无法渲染页面时数据不显示。
回答by BrightIntelDusk
After considering other answers on this question and "How to detect if JavaScript is disabled?" as well as some further research on AngularJS.
在考虑了关于这个问题的其他答案和“如何检测 JavaScript 是否被禁用?”以及对 AngularJS 的一些进一步研究之后。
First off you will want to hide all variables displayed through the databindings.
首先,您需要隐藏通过数据绑定显示的所有变量。
This can be done using ng-cloakwhich is appended to an HTML tag.
这可以使用附加到 HTML 标签的ng-cloak来完成。
<div ng-cloak>
<!-- page content here -->
{{bound_data}}
</div>
It also includes a CSS tag to hide that element.
它还包括一个 CSS 标签来隐藏该元素。
[ng\:cloak], [ng-cloak], [data-ng-cloak], [x-ng-cloak], .ng-cloak, .x-ng-cloak {
display: none !important;
}
You will then want alternate content to be displayed for when a user has JavaScript blocked or disabled. This is done using the tag.
然后,您将希望在用户阻止或禁用 JavaScript 时显示替代内容。这是使用标签完成的。
<noscript>
You must have JavaScript enabled to use this app.
</noscript>
You have the choice to create an app with reduced features and functionality or require the visitor to have JavaScript enabled in order to use your app at all.
您可以选择创建功能较少的应用程序,或者要求访问者启用 JavaScript 才能使用您的应用程序。
回答by z5h
<NOSCRIPT>
You need Javascript enabled to use this site.
</NOSCRIPT>