-2

How can I redirect the whatsapp api link in new page? When I press ok the whatsapp api is open in same page.

The code I have tried so far.

   setTimeout(function () {
      applause.play();
      swal(
        "Congratulations",
        "" + SelectedItem + ".",
        "success"
      ).then(function() {
            window.location.replace("https://api.whatsapp.com/send?phone=+91123456789" );
            });
    }, 5500);
Sarkar
  • 61
  • 2
  • 12
  • https://developer.mozilla.org/en-US/docs/Web/API/Window/open – Quentin May 24 '22 at 12:32
  • *When I press ok the whatsapp api is open in same page.* ... infers that OP is using a copy/paste code snippet from "whatsapp". However since OP doesn't show this code, the question is not debuggable. – mardubbles May 24 '22 at 12:35
  • @mardubbles — Umm. `window.location.replace("https://api.whatsapp.com/send?phone=+91123456789" );` is right there in the question. – Quentin May 24 '22 at 12:41
  • But @Quentin OP says the code that he wants to *modify* is from "whatsapp", which she doesn't show, inferred by *When I press ok*.... what "ok"? – mardubbles May 24 '22 at 12:45
  • @mardubbles — `swal` is quite a well known library. It generates a modal with an OK button. When you click OK the promise resolves which will call the `then` function (which currently loads a whatsapp URL in the same window). – Quentin May 24 '22 at 12:46
  • Ahhh see I didnt know that @Quentin but now do – mardubbles May 24 '22 at 12:47
  • I hadn't even noticed the use of `swal`. It isn't needed to recognise that `window.location.replace` will open the URL (which points to whatsapp's website) in the same tab. – Quentin May 24 '22 at 12:48
  • True @Quentin. I cant really elaborate on my lack of knowledge further. Seems like likely arnaspdk below solves this? – mardubbles May 24 '22 at 12:51

1 Answers1

1
window.open("https://api.whatsapp.com/send?phone=+91123456789", '_blank');
arnaspdk
  • 66
  • 3