0

It worked a year ago, but now it opens a new window/tab (which is the correct behavior), but it stays blank and does not open the URL specified.

I allowed popups in my Chrome setting but still the same result.

Pasting and executing the URL by hand works fine (like https://api.whatsapp.com/send?text=bla ).

<p>
  <span class="tooltip"
    ><i class="fa fa-whatsapp"></i>&nbsp;&nbsp;<a
      id="lblSuccess2"
      href="javascript:sendWA()"
      target="_blank"
      ><span class="tooltiptext" id="myTooltip2"
        >Klik om te delen via WhatsApp</span
      >WhatsApp</a
    ></span
  >
</p>
function sendWA() {
  var tekst = document.getElementById("txtVoorbeeldtekst").value;
  var uriWA = "https://api.whatsapp.com/send?text=".concat(
    encodeURIComponent(tekst)
  );
  window.open(uriWA, "_blank");
  return false;
}
Raghul SK
  • 1,256
  • 5
  • 22
  • 30
leonvr
  • 93
  • 1
  • 14
  • Opening an URL to a popup/tab in Chrome works fine, maybe it's WhatsApp API ..? – Teemu Jul 01 '20 at 11:17
  • WhatsApp API is ok. Opening programmaticaly by Javascript in a new window does not work. – leonvr Jul 01 '20 at 11:26
  • A similar call on my own site works in Chrome (URL has a querystring, and _blank as the name). Have you taken a look at the DevTools, maybe an error has occurred? – Teemu Jul 01 '20 at 11:28
  • Now I notice in the new window I get: VM84:1 Uncaught ReferenceError: sendWA is not defined. How can that be? – leonvr Jul 01 '20 at 11:35
  • Based on the code in the question it's impossible to say. Make sure the script containing `sendWA` is loaded, and the function must also be global. – Teemu Jul 01 '20 at 11:37
  • This answers the question: [Open URL in new window with JavaScript](https://stackoverflow.com/questions/14132122/open-url-in-new-window-with-javascript) – Heretic Monkey Jul 01 '20 at 12:47

1 Answers1

0

I managed to solve the problem. Use onclick instead of href, like this:

href="#" onclick="sendWA(); return false;"
leonvr
  • 93
  • 1
  • 14