Asp.Net - 检测到页面上没有 javascript? (已更名标题)
我有一个页面,在 TabContainer 中显示其所有内容,但如果浏览器上禁用了 javascript,它只会显示一个空白页面。
我可以添加 来显示所有重要内容,但空白 TabContainer 仍会呈现。
我想在标题中添加 a 以重定向到同一页面加上 ?noscript=true ,但它不应该是无限的。我认为使用 PlaceHolder 控件会在当前 url 不存在时放置适当的 具有 noscript 查询值。
然后,当 noscript 查询值存在时,我可以将 TabContainer 的 Visible 属性设置为 false。
这是正确的做法吗?
I have a page that displays all its content in a TabContainer, but if javascript is disabled on the browser it just displays a blank page.
I can add a <noscript>
to display all the important content, but the blank TabContainer still renders.
I'd like to add a in the header to redirect to the same page plus ?noscript=true, but it shouldn't be infinite. I figure using a PlaceHolder control that will put the appropriate <META HTTP-EQUIV="Refresh" CONTENT="0; URL=url?noscript=true">
when the current url doesn't have the noscript query value.
Then I can set the Visible property to false for the TabContainer when the noscript query value is present.
Is this the right way to go about it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 HttpBrowserCapabilitites 类来获取有关浏览器的信息,用于检查 JavaScript 支持的属性称为 EcmaScript 版本。如果版本 >= 1,则浏览器支持 JavaScript。
You can use HttpBrowserCapabilitites class to obtain information about the browser, the property to check for JavaScript support is called EcmaScriptVersion. If it has a version >= 1, the browser supports JavaScript.
我想出了一种可行的方法,但对于 Asp.Net 来说仍然很新,所以我对其他人的想法很感兴趣。
编辑:我通过引入一个临时(仅限会话)cookie 来扩展这个想法,该 cookie 会记住浏览器是否有 NoScript,因此我们不必继续重定向到同一页面,我们只需使用下次请求页面时该 bool 值。
我在母版页的头部执行了此操作:
在 TabContainer 的
Visible="<%# !NoJavascript %>"
属性中。那么在CodeBehind中:
还有其他想法吗?
未来的想法:如果他们没有启用 Cookie,我想将 noscript 查询值传递给每个请求的实用程序也会有所帮助,否则他们将在每个请求上不断重定向到同一页面。
I came up with a method that works, still pretty new to Asp.Net so I'm interested in what others think.
Edit: I expanded on the idea by introducing a temporary (session only) cookie that remembers if the browser has NoScript so we don't have to keep redirecting to the same page, we just use that bool value the next time a page is request.
I did this in the head of the master page:
In the TabContainer's
Visible="<%# !NoJavascript %>"
property.Then in the CodeBehind:
Any other ideas?
Future thought: If they don't have Cookies enabled, I guess a utility to pass the noscript query value to each request would help as well, otherwise they will get continually redirected to the same page on each request.
好吧,因为我很彻底,并且不想重复代码,所以我创建了这个组件来执行我的其他答案,并检查会话和视图状态以进行先前的检测。
该组件的价值在于它可以在其他页面上使用,并且可以访问该组件在其他页面上使用的相同会话/cookie 值。
有什么改进建议吗?
Well, because I'm thorough, and don't want to duplicate code, I created this component that does my other answer plus checks session and viewstate for previous detection.
The value of the component is that it can be used on other pages and it will have access to the same session/cookie value that was used on other pages with the component.
Any suggestions at improvement?