I have tried using header() to programmatically take the user to a different page
in my site after they see then dismiss an alert() box, but it’s not doing what I need.
I need to:
1) have a javascript alert() echoed to the browser
2) then after the alert() box is dismissed, I need to jump to another page
3) saying ‘use ajax’ won’t help me here as I’ve got a full plate just coming to grips with php,
mysql, html5 and javascript. Plate is full, ajax -> later.
In the code below I never see the alert() — my browser just immediately shows me shimmyLogin.php.
If I comment out the ‘header()’ call, then I see my alert() just fine — but then I’m not
doing what I need to do after the alert(), which is to programmatically take my user to shimmyLogin.php.
I’m pretty sure I know why this is happening but my question is — is there a way to
1) pop up an alert() box
2) then after the user dismisses the alert(), I can then do a header() (or some other way)
to jump to my other page shimmyLogin.php?
I’m really new to programmatically navigating the pages of a site and I’m aware of header()
but obviously it will not work here for the 2 things I need to do above.
Here’s the code:
if(showAlertBox("Unexpected error! "))
{
header('Location: http://localhost/shimmyDooHah/shimmyLogin.php');
}
where showAlertBox is just:
function showAlertBox($messageToDisplay)
{
echo '<script type="text/javascript">'
. 'alert("' . $messageToDisplay . '")</script>';
return true;
}
In your showAlertBox() – you need to add after the alert(“bla-bla”); this line:
It will take the user to the url you will put there.