我希望如果浏览器的javascript被关闭,用户应该被重定向到一个新页面。。。
我试过这样做,但没有成功。。。<noscript><?php header("location: js-error.php"); ?></noscript>
此脚本将页面重定向到js-error.php,即使javascript为ON。
这不起作用,因为在发送输出后无法设置header()
。
请记住,必须在调用任何实际输出之前调用header()通过普通HTML标记、文件中的空行或PHP发送。
这样做的方法是使用meta-refresh
,尽管有些浏览器可能不遵守此指令。例如:
<meta http-equiv="refresh" content="0; url=http://example.org">
我喜欢的方法是根本不重定向,而是显示一个简单的模态(使用直接的CSS),告诉他们如何启用JavaScript。在"让我有一个博客"上有一个我提倡的信息类型的例子。
替代方式:
<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
您将两种技术混合在一起。php调用从服务器端重定向您,甚至在页面完全呈现以发送到客户端之前。