0

I need to adjust this popup alert so that if the user clicks "cancel" it will cause them to stay on the same page (instead of being redirected to the page from the link they clicked on). Here's what I'm working with:

function myFunction() {
var txt;
if (confirm("Are you sure you want to move on? Your work on this passage 
will be lost.")) {

} else {
}

Could you give me some tips? Thanks!

Eva
  • 37
  • 1
  • 1
  • 4
  • What have you tried? `window.location` would probably be what you're looking for. https://stackoverflow.com/questions/503093/how-do-i-redirect-to-another-webpage – rickjerrity Aug 16 '18 at 21:49

2 Answers2

0

Try this:

function myFunction() {
    var txt;
    if (confirm("Are you sure you want to move on? Your work on this passage 
    will be lost.")) {

    } else {
              window.history.back();
    }
Red Lemon
  • 69
  • 6
0

With this it stays on the current page, unless the user clicks ok.

function myFunction() {
    var redirect_url = 'http://whatever.com';
    if (window.confirm("Are you sure you want to move on? Your work on this passage will be lost.")) {
        window.location(redirect_url);
    }
}
cannon
  • 61
  • 2
  • Thank you for your answer! It almost works, except that now the user isn't redirected upon clicking 'OK' and I must be missing simple but I'm not sure what... I used the following code: `function previousPassage() { var redirect_url = 'https://www.enewsdispatch.com/rc-strategy/'; if (window.confirm("Are you sure you want to move on? Your work on this passage will be lost.")) { window.location(redirect_url); } }` – Eva Aug 24 '18 at 18:17