Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect to other page on alert box confirm [duplicate]

Tags:

javascript

This is a piece of my function with the question in it:

function deletePost() {     var ask = window.confirm("Are you sure you want to delete this post?");     if (ask) {         window.alert("This post was successfully deleted.");          /* How to redirect to another page on confirm? */      } } 

Pure Javascript needed.

like image 580
Hypn0tizeR Avatar asked Sep 25 '12 22:09

Hypn0tizeR


People also ask

How do I get alert messages after redirecting a page?

You cannot run an alert after the location. href has changed because it causes the browser to refresh. Once refreshed, your script is no longer running. You would need to move your alert script into your search page and perhaps pass the name as a querystring arguement.

What is confirm() in HTML?

confirm() instructs the browser to display a dialog with an optional message, and to wait until the user either confirms or cancels the dialog.

How do I redirect after a few seconds?

To redirect URL to a different website after few seconds, use the META tag, with the content attribute.


1 Answers

try this:

function deletePost() {     var ask = window.confirm("Are you sure you want to delete this post?");     if (ask) {         window.alert("This post was successfully deleted.");          window.location.href = "window-location.html";      } } 
like image 66
kingkode Avatar answered Sep 21 '22 15:09

kingkode