0

I would like to redirect users as and when click "OK" in the alert box. Any hints will be appreciated

if( $num_rows == 0 ) {
    // No results returned
    echo "No results!";
} else {
    $message = "Information already sent";
echo "<script type='text/javascript'>alert('$message');</script>";
}
rns
  • 92
  • 10
  • 1
    http://stackoverflow.com/questions/37114003/how-to-move-to-another-page-after-displaying-javascript-alert/37114208#37114208 – Devsi Odedra Jun 08 '16 at 09:01

4 Answers4

2
echo "<script type='text/javascript'>
   alert('$message');
   document.location.href='your url';
</script>";
nospor
  • 4,190
  • 1
  • 16
  • 25
0

You can use window.location.href to redirect to any page in javascript, so that it will be redirected to test.php after use click OK in alertbox:

if( $num_rows == 0 ) {
    // No results returned
    echo "No results!";
} else {
    $message = "Information already sent";
    echo "<script type='text/javascript'>alert('$message');window.location.href='test.php';</script>";
}
Dhara Parmar
  • 8,021
  • 1
  • 16
  • 27
0
echo "<script>alert('Update Not Successfully');document.location='pagename.php'</script>";
Devsi Odedra
  • 5,244
  • 1
  • 23
  • 37
0

Using window.location.replace(url) is better, than window.location.href = url, because is disallows user to go back at this page using button "previous page in history" in browser.

It does a real redirect instead of just going to the next url:

if( $num_rows == 0 ) {
    // No results returned
    echo "No results!";
} else {
    $message = "Information already sent";
    echo "<script type='text/javascript'>alert('$message'); window.location.replace('test.php'); </script>";
}
Nikolai Saiko
  • 1,679
  • 26
  • 27