How to reload a page after the OK click on the Ale

2019-02-08 21:08发布

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

10条回答
The star\"
2楼-- · 2019-02-08 21:44

Try this:

alert("Successful Message");
location.reload();
查看更多
smile是对你的礼貌
3楼-- · 2019-02-08 21:47

use confirm box instead....

    var r = confirm("Successful Message!");
    if (r == true){
      window.location.reload();
    }
查看更多
何必那么认真
4楼-- · 2019-02-08 21:49

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!? :)

查看更多
聊天终结者
5楼-- · 2019-02-08 21:49

I may be wrong here but I had the same problem, after spending more time than I'm proud of I realised I had set chrome to block all pop ups and hence kept reloading without showing me the alert box. So close your window and open the page again.

If that doesn't work then you problem might be something deeper because all the solutions already given should work.

查看更多
登录 后发表回答