如果 javascript 被禁用,则重定向到另一个页面

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8355359/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 03:11:04  来源:igfitidea点击:

redirect to another page if javascript is disabled

javascriptasp.net

提问by Shah

i have a alot of functionality implemented through javascript if at any stage the javascript is disabled he should be redirected to another page. mentioning him to enable the javascript and then proceed. and this functionality should be cross browser compatable Regard,

我有很多功能是通过 javascript 实现的,如果在任何阶段禁用 javascript,他应该被重定向到另一个页面。提到他启用javascript然后继续。这个功能应该是跨浏览器兼容的

回答by Rohan Patil

Use <noscript> tag to check whether JavaScript is enabled or not.<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.google.com/">will redirect it to the specified url.Here in this example it will redirect to the google.

使用<noscript> 标签检查 JavaScript 是否启用。<meta HTTP-EQUIV="REFRESH" content="0; url=http://www.google.com/">将其重定向到指定的 url。在本例中,它将重定向到 google。

Here is an example.

这是一个例子。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title>How To Detect If User Javascript Is Enabled</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <style type="text/css">
    <!--
    .style1 {
    color: #FF0000;
    font-weight: bold;
    }
    -->
    </style>
    </head>
    <body>
    <p>The Purpose of this script is to show if you have javascript enabled in your browser.</p>
    <p class="style1">
    <script type="text/javascript">
    document.write('Javascript is enabled');
    </script>
    <noscript>
    Javascript is disabled.
    <meta HTTP-EQUIV="REFRESH" content="0; url=http://www.google.com/"> 
     </noscript>
    </p>
  </p>
    </body>
    </html>

回答by Bas Slagter

Do a http redirect from a noscript block. Like:

从 noscript 块执行 http 重定向。喜欢:

<noscript>
    <meta HTTP-EQUIV="REFRESH" content="0; url=http://www.yourdomain.com/index.html"> 
</noscript>

回答by Oded

Use the noscriptelement with a metaredirect.

使用noscript带有meta重定向的元素。

回答by SaQiB

You could try this, this will write the message that the javascript is not enabled and refreshes in 5 seconds

你可以试试这个,这会写出javascript未启用并在5秒内刷新的消息

<noscript>
Javascript is not enabled in your browser, you'll be redirected to another page.
    <meta HTTP-EQUIV="REFRESH" content="5; url=http://www.mysite.com/nojavascript.html"> 
</noscript>

回答by sushil bharwani

I think the noscript Tag will be helpful in this case. This will execute when javascript is disable. So in this you can have a meta redirect useful

我认为 noscript 标签在这种情况下会有所帮助。这将在禁用 javascript 时执行。所以在这个你可以有一个有用的元重定向