在调用javascript警报后,我在执行php重定向时遇到了一些问题。代码如下:
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>';
希望这能帮助您
这是你能做的最好的使用:-
窗口位置
http://www.w3schools.com/js/js_window_location.asp
尝试这种方式
echo '<script>window.alert("This device is aleady registered to another user");
window.location.href = "page.php";
</script>';