javascript - php 页面跳转

WBOY
Release: 2016-06-06 20:10:51
Original
803 people have browsed it

这样写可以正常跳转:

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

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

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

回复内容:

这样写可以正常跳转:

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

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

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

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

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

楼上仁兄正解

<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>
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template