rns
rns

Reputation: 92

Alert box pops up - redirect on click "OK"

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>";
}

Upvotes: 0

Views: 942

Answers (4)

Nikolai Saiko
Nikolai Saiko

Reputation: 1708

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>";
}

Upvotes: 0

Devsi Odedra
Devsi Odedra

Reputation: 5322

echo "<script>alert('Update Not Successfully');document.location='pagename.php'</script>";

Upvotes: 0

Dhara Parmar
Dhara Parmar

Reputation: 8101

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>";
}

Upvotes: 0

nospor
nospor

Reputation: 4220

echo "<script type='text/javascript'>
   alert('$message');
   document.location.href='your url';
</script>";

Upvotes: 2

Related Questions