Home  >  Article  >  Backend Development  >  javascript - php 页面跳转

javascript - php 页面跳转

WBOY
WBOYOriginal
2016-06-06 20:10:51767browse

这样写可以正常跳转:

<code>echo "<script>";
echo "window.location.href = '$url'";
echo "</script>";</code>

而下面代码服务器返回空白页面,没有执行我的命令,请问是怎么回事?php小白,照葫芦画瓢写的代码:

<code>echo "<script>";
echo "function()
{
   alert($error_msg);
   setTimeout(window.location.href = '$url',5);
}";                    
echo "</script>";
    </code>

回复内容:

这样写可以正常跳转:

<code>echo "<script>";
echo "window.location.href = '$url'";
echo "</script>";</code>

而下面代码服务器返回空白页面,没有执行我的命令,请问是怎么回事?php小白,照葫芦画瓢写的代码:

<code>echo "<script>";
echo "function()
{
   alert($error_msg);
   setTimeout(window.location.href = '$url',5);
}";                    
echo "</script>";
    </code>

setTimeout(func,5);
前面func是一个方法

<code>echo "<script>";
echo "function func()
{
   alert($error_msg);
   window.location.href = '$url';
}";
setTimeout(func,5);                    
echo "</script>";</code>

楼上仁兄正解

<code><?php $url = "http://www.baidu.com";
$error_msg = "error";
echo "<script>";
echo "function jump()
{
   alert('$error_msg');
   window.location.href = '$url';
}
setTimeout(jump, 3000);
";                    
echo "";</code>

你js部分只是定义了函数没有调用啊

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn