ASP.NET,检查禁用JavaScript? [英] ASP.NET, check for javascript disabled?

查看:167
本文介绍了ASP.NET,检查禁用JavaScript?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白如何运作的ECMAScript。检查MSDN和其他论坛,它没有告诉我们哪一个版本或值等于javascrpt。

I don't understand how does ECMAScript works. Check on MSDN and other forum it didnt tell us which version or values equal to javascrpt.

if (!Request.Browser.JavaScript)
 //Do Something.

不过,我得到obsolute的警告,并建议我使用的ECMAScript来代替。

However, I was given a warning of obsolute and recommend me to use ECMAScript instead.

System.Web.HttpBrowserCapabilities myBrowserCaps = Request.Browser;
if (((System.Web.Configuration.HttpCapabilitiesBase)myBrowserCaps).EcmaScriptVersion.Major < 1)
//Does not have Javascript. Do something.

不过,我都试过开/关我的JavaScript。不知怎的,功能没有被解雇。我怀疑某些值属于的JavaScript。但是,我找不到任何有关值== JavaScript的。

However, I tried both on/off my javascript. Somehow the function was not fired. I suspect certain values belong to javascript. However, I cant find anything related to value == javascript.

我明白我可以一个接着使用元标签执行重定向。不过,我想所有这些code。在服务器上执行。

I understand I could a Then perform a redirect using meta tag. But I would like all these code to perform at the server.

推荐答案

首先,看<一个href=\"http://programmers.stackexchange.com/questions/25969/should-i-bother-to-develop-for-javascript-disabled\">Should我懒得制定禁用了JavaScript? / <一个href=\"http://programmers.stackexchange.com/questions/23535/how-important-is-graceful-degradation-of-javascript\">How重要的是JavaScript?的功能退化。

First of all, see Should I bother to develop for JavaScript disabled? / How important is graceful degradation of JavaScript? .

然后,客户端Javascript只存在于客户端,如果它是关闭,无客户端逻辑将触发明确检查什么。所以,你可以不知道它,直到客户从你的网页发送至少一个答复(无论是GET / POST查询或XMLHTT prequest) - 即只从非常用户第二个请求后,由非常页面您生成送他们,如果他们只是潜伏在其中可能永远不会发生,即使你做的每一个环节你的页面上的表单回复 - 他们可能使用的URL从外部来源。从检查是否禁止javascript?一个例如,这种方法的。

Then, client-side Javascript only exists in the client and if it's off, no client-side logic will fire to check anything explicitly. So you cannot know it until the client sends at least one reply from your page (be it a GET/POST query or an XMLHTTPRequest) - i.e. only after the second request from that very user, generated by the very page you sent them, which may never occur if they just lurk around, even if you make every link on your page a form reply - they may use URLs from an external source. A CodeProject article linked from Check if javascript is disabled? is one example of such approach.

由于这个原因(并避免重复工作,使两个剧本和无脚本版本 - 即看到,在过去的一些使用习惯),最好的做法似乎已经成为制作网页和框架的JavaScript无关,只是警告用户与&LT; NOSCRIPT方式&gt; 的网页可能无法完全发挥作用,如果是相关的

For this reason (and to avoid effort duplication to make both script and noscript versions - the practice that saw some use in the past), the best practice appears to have become making pages and frameworks JavaScript-agnostic and just warning the user with <noscript> that the page may not be fully functional if it's relevant.

例如。 Sharepoint的做到了这一点 - 与JS禁用,警告在上面,同时在页面上,还有如出现没有滚动条和编辑已完全被禁用。 这导致了ASP.NET控件的结论(这SP大量使用)的目的不是超越与JS基本陈列摆在首位禁用功能。

E.g. Sharepoint does just that - with JS disabled, a warning appears on top while on the page, there are e.g. no scrollbars and editing is disabled completely. Which leads to conclusion that ASP.NET controls (which SP makes heavy use of) weren't designed to be functional beyond basic display with JS disabled in the first place.

这篇关于ASP.NET,检查禁用JavaScript?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆