没有脚本标签的问题

发布于 2024-09-17 00:05:37 字数 300 浏览 0 评论 0原文

我在我的母版页上没有放置任何脚本标记,如果用户没有启用 javascript 或者其浏览器不支持 javascript,它会重定向到特定视图。我正在使用这段代码

 <noscript>    
  <% Response.Redirect("../UserLogin/Error");  %>
 </noscript>

,但问题是每次我打开页面时它都会重定向我,尽管我的 javascript 已启用。我使用 asp.net mvc2 可能有什么问题或者有其他方法可以做到这一点吗?

Im placing no script tag on my master page that if a user dont have javascript enabled or its browsers doesnt support javascript it redirect to a specific view. im using this code

 <noscript>    
  <% Response.Redirect("../UserLogin/Error");  %>
 </noscript>

but the problem is its redirecting me everytime i open the page although my javascript is enabled. Im using asp.net mvc2 what may be the problem or is there is any other way to do this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蓝海似她心 2024-09-24 00:05:44

标签 noscript 在客户端(浏览器)中进行评估。服务器不知道客户端是否有脚本支持,所以每次都会重定向。


编辑

更好地解释一下:服务器只是创建一个字符串(HTML)并将其发送到浏览器。它不会解析浏览器是否支持脚本。


编辑2

您可以使用元刷新标签。请参阅:

<head>
    <noscript>
    <meta http-equiv="refresh" content="0;url=http://example.com/" />
    <!-- Redirect to http://example.com/ immediately -->
    </noscript>
</head>

我在 Firefox 中测试并有效。

The tag noscript is evaluated in the client (browser). The server doesn't know if client has script support, so every time it redirects.


EDIT

Explain better: the server just creates a string (HTML) and send it to browser. It doesn't parse to see if browser has script support.


EDIT 2

You can use meta refresh tag. See:

<head>
    <noscript>
    <meta http-equiv="refresh" content="0;url=http://example.com/" />
    <!-- Redirect to http://example.com/ immediately -->
    </noscript>
</head>

I tested in firefox and works.

极度宠爱 2024-09-24 00:05:42

Response.Redirect 在服务器端执行,它会向浏览器发送 302 状态码,浏览器会自动重定向。您可能想要:

<noscript>    
    Please enable javascript to use this site.
</noscript>

Response.Redirect is executed on the server side and it will send a 302 status code to the browser which will automatically redirect. You probably want:

<noscript>    
    Please enable javascript to use this site.
</noscript>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文