问题描述
在一个ASP.NET Web的控制的Render方法,我需要改变的HTML根据输出的JavaScript是否被启用或禁用客户端上的浏览器中,
In the Render method of an ASP.NET web-control, I need to alter the output of the Html based on whether JavaScript is enabled or disabled on the clients browser,
有谁知道正确的咒语,明白这一点?
Does anyone know the right incantation to figure that out?
推荐答案
使用脚本来检查启用javascript是否是,你只发现了脚本无法运行后的问题。
The problem with using script to check whether javascript is enabled is that you only find that out after the script hasn't run.
一些解决方案尝试相反 - 他们使用JavaScript来设定一个值,然后提供启用Javascript控制如果以后检测到的价值。但是,这种失败,支持JavaScript的有时是工具,如Firefox的NoScript的插件。
Some solutions try the opposite - they use javascript to set a value and then supply Javascript enabled controls if that value is later detected. However, this fails with javascript-sometimes-enabled tools like the Firefox NoScript plugin.
一个更强大的解决方案是始终发送纯HTML兼容的控制,然后对页面加载的JavaScript运行添加正确的处理事件/额外的DOM元素的/ etc。
A more robust solution is to always send the plain-HTML compatible control, and then have javascript run on page load to add the correct event handlers/extra DOM elements/etc.
不过,我不知道如何适应与ASP.NET方法利用管制。
However I don't know how this fits in with the ASP.NET approach takes to controls.
这篇关于JavaScript时在ASP.NET中禁用检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!