简体   繁体   English

如何检测(使用.ASPX)是否在浏览器上启用了Javascript

[英]How to detect (using .ASPX) if Javascript is enabled on browser

I'm thinking this might be a quick and easy way to lower the form spam on our site just a little bit. 我认为这可能是减少我们网站上的垃圾表单的快速简便方法。 The idea being that (I have read) spammers aren't running with javascript enabled. 想法是(我已阅读)垃圾邮件发送者未在启用javascript的情况下运行。 (Or at least they are accessing your website without running javascript. Ie, they aren't browsing up to it in IE or FF. (或者至少他们是在没有运行javascript的情况下访问您的网站。也就是说,他们没有在IE或FF中浏览该网站。

I can use .asp or .aspx. 我可以使用.asp或.aspx。

The simplest way is to set a cookie via javascript and check for it on postback.However, if you're looking to minimize spam you should actually have the browser perform a simple task which requires javascript execution. 最简单的方法是通过javascript设置cookie并在回发时检查它。但是,如果您希望最大程度地减少垃圾邮件,则实际上应该让浏览器执行一个简单的任务,该任务需要执行javascript。 See Phil Haack's "Invisibile Captcha Validator" control, which has since been included in his Subkismet library: http://haacked.com/archive/2006/09/26/Lightweight_Invisible_CAPTCHA_Validator_Control.aspx 请参阅Phil Haack的“ Invisibile Captcha Validator”控件,此控件已包含在他的Subkismet库中: http ://haacked.com/archive/2006/09/26/Lightweight_Invisible_CAPTCHA_Validator_Control.aspx

To be honest, you shouldn't need to use a server-side language to detect javascript, and furthermore spammers are not necessarily not running javascript. 老实说,您不需要使用服务器端语言来检测javascript,此外,垃圾邮件发送者不一定未运行javascript。 (sorry about the double-negative) Your objective is good, but your approach is wrong - implementing a CAPTCHA, as suggested by a few of our peers, would be a great way to handle this. (对双重否定表示抱歉)您的目标是好的,但是您的方法是错误的-如我们的一些同行建议的那样,实施验证码将是解决此问题的好方法。

In .net, you can use Request.Browser.JavaScript to detect if the browser supports JavaScript. 在.net中,可以使用Request.Browser.JavaScript来检测浏览器是否支持JavaScript。 However, the user may still have Javascript disabled. 但是,用户可能仍然禁用了Javascript。 An ugly way to check to see if Javascript is enabled, is to use window.location to redirect to page.aspx?jscript=true, and then check Request.Querystring for that value. 检查是否已启用Javascript的一种丑陋方法是使用window.location重定向到page.aspx?jscript = true,然后检查Request.Querystring中的值。

So, you want to force users to use JavaScript in order to use your site? 因此,您要强制用户使用JavaScript才能使用您的网站吗? I'd rather just use a simple Captcha. 我宁愿只使用一个简单的验证码。 If you aren't a big-name site, you can get away with some relatively simple Captchas. 如果您不是知名网站,则可以使用一些相对简单的验证码。

That's how we reduced spam at our site. 这就是我们减少网站垃圾邮件的方式。

I see you've accepted the noscript answer, but how will you use this to fight spam? 我看到您已经接受了noscript答案,但是您将如何使用它来打击垃圾邮件? noscript will allow you to add special content for users without JS, but unless you're generating the rest of your site in JS, it will still be available to user agents without JS. noscript允许您为没有JS的用户添加特殊内容,但是除非您在JS中生成网站的其余部分,否则没有JS的用户代理仍然可以使用它。

A captcha of some sort is still likely the best bet. 某种形式的验证码仍然可能是最好的选择。 Ultimately, you're trying to get the user agent to prove that it's being controlled by a human, so do your best to make it prove that actual fact, instead of something else. 最终,您试图让用户代理证明它是由人控制的,因此请尽最大努力使它证明是真实的事实,而不是其他事情。 Screen readers for the visually impaired typically go without Javascript, too, and many people browsing from mobile devices have Javascript disabled to speed things up. 视障人士的屏幕阅读器通常也没有Java脚本,并且许多从移动设备浏览的人都禁用了Java脚本以加快速度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM