How to reload a page after the OK click on the Alert Page

Nabeel Arshad picture Nabeel Arshad · Jun 6, 2013 · Viewed 113.7k times · Source

I need to reload the page after the OK button is clicked on the Alert box. I am using the following code for it

alert("Successful Message");
window.location.reload();

But the window is reloaded immediately after displaying the alertbox. Please Help me in it

Answer

Bojan Milic picture Bojan Milic · Oct 29, 2013

Confirm gives you chance to click on cancel, and reload will not be done!

Instead, you can use something like this:

if(alert('Alert For your User!')){}
else    window.location.reload(); 

This will display alert to your user, and when he clicks OK, it will return false and reload will be done! :) Also, the shorter version:

if(!alert('Alert For your User!')){window.location.reload();}

I hope that this helped!? :)