29

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.

Hypn0tizeR
  • 794
  • 2
  • 11
  • 23

1 Answers1

33

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";

    }
}
kingkode
  • 2,220
  • 18
  • 28
  • 1
    This worked, I've tried to redirect by this way: `window.location = "http://link.com"`, and this did not work. Thank you. – Hypn0tizeR Sep 25 '12 at 22:30
  • 2
    Perfect, I had an almost identical problem and this also saved me. Why won't the other two options work?http://stackoverflow.com/questions/503093/how-can-i-make-a-redirect-page-in-jquery-javascript – null Aug 11 '13 at 10:02
  • 1
    those 2 answers on the link work just fine.. my `document` should be `window` though (amazing what i missed a year ago).. this function shows a confirmation of an action then redirects to specific location.. redirects can be achieved several ways, the above is just one.. – kingkode Aug 13 '13 at 14:37