Asp.Net-如果未启用JavaScript,则重定向 [英] Asp.Net - Redirect if JavaScript is not enabled
问题描述
我在母版"页面中获得了此代码:
I got this code in my Master page :
<script type="text/javascript">
$("#<%=hfJavaScriptDetected.ClientID %>").val('yes');
</script>
<asp:HiddenField ID="hfJavaScriptDetected" runat="server" Value="no" />
因此,如果启用了JavaScript,则应该更改了我的隐藏字段的值.
So if JavaScript is enabled the value of my hidden field should have be changed.
现在,我想在服务器端检查此值,如果将其设置为"no",我想将用户重定向到页面Javascript.Aspx.
Now, what I would like to do is check this value on server side and if it's set to "no", I want to redirect the user to the page Javascript.Aspx.
我不知道在哪个事件中查找隐藏字段的值.我尝试了Page_Load事件,但似乎尚未设置隐藏字段值.
I don't know in which event to look the hidden field value. I try on the Page_Load event but it's seems the hidden field value was not already set.
推荐答案
这样难道不是那么容易吗?
would this not be easier like this?
<noscript>
<meta http-equiv="refresh" content="1;URL=http://www.mysite.com/Javascript.Aspx"/>
</noscript>
如果浏览器启用了javascript,则内部内容将被忽略...但是,如果没有,则 1 秒内,刷新该页面...,新的URL是... Javascript.Aspx
If the browser has javascript enabled, the inner content is ignored... but if they don't the meta tag says, in 1 second, refresh this page... and the new URL is ...Javascript.Aspx
这篇关于Asp.Net-如果未启用JavaScript,则重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!