我无法在noscript上重定向页面

时间:2012-03-30 10:49:12

标签: php javascript html

我希望如果关闭浏览器的javascript,则应将用户重定向到新页面...

我尝试过这种方式,但没有工作...... <noscript><?php header("location: js-error.php"); ?></noscript>

即使javascript为ON,此脚本也会将页面重定向到js-error.php。

3 个答案:

答案 0 :(得分:5)

这不起作用,因为在发送输出后无法设置header()

  

请记住,在任何实际输出之前必须调用header()   通过普通HTML标记,文件中的空行或PHP发送。

执行此操作的方法是使用meta-refresh,但某些浏览器可能不遵守此指令。例如:

<meta http-equiv="refresh" content="0; url=http://example.org">

我首选的方法不是重定向,而是显示一个简单的模态(使用直接的CSS)告诉他们如何启用JavaScript。 Let me have a blog上有一个我所倡导的消息类型的例子。

答案 1 :(得分:3)

替代方式:

<noscript>
<!--
    meta-tag "refresh" is provided for those browsers that
    do not support JavaScript.  Please note that the time
    delay is greater than zero.

    Notice that this is nested within a "noscript" block.
    Which means that browsers that support JavaScript will
    not "see" the refresh meta-tag.
-->
<meta http-equiv="refresh" content="2; URL=redirectiontarget.htm">
</noscript>

http://grizzlyweb.com/webmaster/javascripts/redirection.asp

答案 2 :(得分:1)

您将两种技术混合在一起。 php调用会将您从服务器端重定向,甚至在页面完全呈现以发送给客户端之前。