3

I want to redirect page after clicking an alert box "OK" button

This is my code, but this is not working. The alert box is coming up but when I press OK button it redirects to the same page. I want to redirect http://localhost/project/index.php/Con_Group_View this page.

else
{
    echo '<script type="text/javascript">';
    echo'alert("Your Group Already Created ");';
    echo 'window.Location="http://localhost/project/index.php/Con_Group_View";';
    echo '</script>';
}
Blue
  • 22,608
  • 7
  • 62
  • 92
qwerty
  • 183
  • 1
  • 2
  • 6

2 Answers2

2

You want window.location.href = "http://localhost/project/index.php/Con_Group_View" not window.Location. Remember, names are case-sensitive in javascript.

Also note this is a duplicate of How to redirect to another webpage in JavaScript/jQuery?

Community
  • 1
  • 1
Sherif
  • 11,786
  • 3
  • 32
  • 57
1

It is

echo '<script type="text/javascript">';
echo'alert("Your Group Already Created ");';
echo 'window.location = "http://localhost/project/index.php/Con_Group_View";';
echo '</script>';

JavaScript is case-sensitive, there is a difference between window.location and window.Location

Velko Georgiev
  • 684
  • 4
  • 11
  • @Veiko This worked perfectly for me. I had an alert that when clicking "Ok", would just take you back to the page, but the page was dead. You had to do one more click on anything that did a refresh. Now it takes me directly to the login page. Thank you! window.location=etc etc did the trick. – DevOpsSauce Sep 12 '16 at 06:21