0

这是我想用于重定向的脚本:

<form id="form1" method="post" action="http://yahoo.com">
<script language="javascript" type="text/javascript">
    document.getElementById('form1').submit();
</script>
</form>

现在我必须用一个 php 代码来控制它,但是这个不起作用:

 $redirect = '<form id="form1" method="post" action="http://google.com">
 <script language="javascript" type="text/javascript">
    document.getElementById('form1').submit();
 </script>
</form>' 

我想有一个语法错误,但我无法弄清楚。请帮忙。

还让我知道它是否是一种可以将脚本执行页面保持为引荐来源的重定向方法?

4

2 回答 2

3

You are getting the ' wrong inside getElementById

$redirect = '<form id="form1" method="post" action="http://google.com">
 <script language="javascript" type="text/javascript">
    document.getElementById("form1").submit();
 </script>
</form>' 

By the way, this is a unusual way of doing the redirect. Why not use window.location.href instead?

Or a PHP header redirect?

header("Location: http://www.google.com/");
于 2013-05-08T13:17:57.217 回答
1

Try this, you need to escape single quotes

$redirect = '<form id="form1" method="post" action="http://google.com"> <script language="javascript" type="text/javascript">
document.getElementById(\'form1\').submit(); </script></form>';
于 2013-05-08T13:18:59.940 回答