我的aspx页面中有以下代码,只有当javascript从浏览器中禁用时,Javascript is disbaled才会出现
<div id="jsDiv" runat="server">
<noscript>
Javascript is disbaled
</noscript>
</div>在C#代码中,如果我在任何时候得到innerText或jsDiv的innerHtml,它将得到div内容的相同结果,无论是启用javascript,还是禁用.
我的问题是:如何检测浏览器中用户从C#代码中出现的div的当前innerText ?
发布于 2010-07-30 17:55:14
index.html
<html>
<head>
<!-- Redirect in 10 seconds -->
<meta http-equiv="refresh" content="10;url=http://localhost/Default.aspx" />
<script>
<!-- Redirect to same page, with querystring js = true -->
window.location="http://localhost/Default.aspx?js=true";
</script>
</body>
Redirecting to new page <noscript>that does not need javascript</noscript>
</body>
</html>在默认的asp.net页面中,您可以检查Request.QueryString"js“是否支持javascript。
发布于 2010-06-29 04:58:09
要检测Javascript是否已启用,您只需让JS以某种方式更改某些请求,以表明它的存在。
例如,您可以重写某些链接的href,或者填写表单input值,或者(可能是最好的选项)将AJAX请求发送回服务器。然后,服务器应该存储此特定会话已启用JS,并对未来的请求采取必要的操作。
发布于 2010-06-29 04:58:24
无法使用服务器控件检测浏览器是否打开当前页面的Javascript。原因:您正试图预测未来,因为页面尚未发送到客户端!
使用nick的答案技术检测JS,然后将答案存储在用户的会话中。
添加:见http://www.codeproject.com/KB/user-controls/CheckJavascriptEnabled.aspx
https://stackoverflow.com/questions/3137930
复制相似问题