I'm having some troubles getting a php redirect to execute after a javascript alert is called. The code is below:
echo '<script>window.alert("This device is aleady registered to another user");</script>';
header('Location: page.php');
After clicking "OK" on the alert, the redirect does not execute. Any thoughts as to how I can get this code working?
Thanks
You can't send headers after your output. Just redirect the user thru javascript all the way instead.
echo '<script>window.location.href = "page.php";</script>';
You can't output anything before calling header
, not even a single space. You can use header before outputting the script like in the code below
header('Location: page.php');
echo '<script>window.alert("This device is aleady registered to another user");</script>';
Hope this helps you
This is the best you can do use :-
window.location
try this way
echo '<script>window.alert("This device is aleady registered to another user");
window.location.href = "page.php";
</script>';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.