我有一些麻烦让一个JavaScript重定向在调用javascript警报后执行。代码如下:php代码在调用javascript警报后没有执行
echo '<script>window.alert("This device is aleady registered to another user");</script>';
header('Location: page.php');
单击警告中的“确定”后,重定向不会执行。有关我如何获得此代码的任何想法?
谢谢
我有一些麻烦让一个JavaScript重定向在调用javascript警报后执行。代码如下:php代码在调用javascript警报后没有执行
echo '<script>window.alert("This device is aleady registered to another user");</script>';
header('Location: page.php');
单击警告中的“确定”后,重定向不会执行。有关我如何获得此代码的任何想法?
谢谢
您不能在输出后发送标题。相反,只需通过JavaScript重定向用户。
echo '<script>window.location.href = "page.php";</script>';
可以在调用header
,甚至不是一个单一的空间之前,不能输出任何东西。您可以在代码输出脚本像下面
header('Location: page.php');
echo '<script>window.alert("This device is aleady registered to another user");</script>';
希望之前使用头这可以帮助你
试试这个方法
echo '<script>window.alert("This device is aleady registered to another user");
window.location.href = "page.php";
</script>';
请检查我的答案 – 2014-08-30 04:59:02