How to reload the page after clicking OK on the notification page

I need to reload the page after clicking OK in the "Warning" field. I use the following code for it

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

But the window restarts immediately after the notification window is displayed. Please help me with this.

+7
source share
10 answers

Confirm, you can click cancel, and the reboot will fail!

Instead, you can use something like this:

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

This will display a warning for your user, and when he clicks OK, he will return false and the reboot will be done! :) Also, a shorter version:

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

I hope this helps !? :)

+27
source

Use javascript confirm() method instead of warning. It returns true if the user clicked the ok button and returns false when the user clicked the cancel button. Sample code will look like this:

 if(confirm('Successful Message')){ window.location.reload(); } 
+4
source

use the confirmation field instead.

  var r = confirm("Successful Message!"); if (r == true){ window.location.reload(); } 
+3
source
 alert('Alert For your User!') ? "" : location.reload(); 

You can also write the code above in this format. It seems pretty decent.

+3
source

Interestingly, Firefox will stop further JavaScript processing after the move function. Chrome and IE will continue to display any other warnings, and then reload the page. Try:

 <script type="text/javascript"> alert('foo'); window.location.reload(true); alert('bar'); window.location.reload(true); alert('foobar'); window.location.reload(true); </script> 
+1
source

Try the following:

 alert("Successful Message"); location.reload(); 
+1
source

Boyan Milich answers the question, but he is mistaken with the message below,

enter image description here

This can be avoided

 function message() { alert("Successful message"); window.location = 'url_Of_Redirected_Page' // ie window.location='default.aspx' } 
+1
source

Since the alert method in JavaScript does not return a boolean or returns the current thread, you should use a different method.

My number one recommendation is a little CSS experience. Instead, you should create a div element that is fixed positionally.

Otherwise, you can use the confirm () method.

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

However, this will add a cancel button. Since the confirmation method is not part of the if statement, the cancel button still refreshes the page the way you want it.

0
source

Maybe I'm wrong, but I had the same problem after spending more time than I'm proud of. I realized that I installed chrome to block all pop-ups and therefore continue to reboot without showing me a warning window. So close the window and open the page again.

If this does not work, then the problem may be something deeper, because all the solutions provided should work.

0
source

Try this code ..

In php code

 echo "<script type='text/javascript'>". "alert('Success to add the task to a project.'); location.reload;". "</script>"; 

In javascript

 function refresh() { alert("click ok to refresh page"); location.reload(); } 
0
source

All Articles