Whatsapp link - dynamic link for share

0 votes
200 views
added Jan 12, 2022 in Software & tools by lcjr Lieutenant (12,010 points)
edited Jan 12, 2022 by lcjr
$('#whatsappBtn').click(function(){
  var whatsAppPhone = '60123456789',
      whatsappPhone2 = '601233445566'; 
  var defaultMessage = "";
  var url = window.location.href;
  if(url.includes('1860554')) {
    defaultMessage = "1860554 message goes here:";
  } else if(url.includes('1901663')) {
    defaultMessage = "whatsappPhone2 message goes here:";
  }
    else {
    defaultMessage = "Default message goes here:";
  } 

  if(url.includes('1901663')) {
    window.open(
      "https://wa.me/"+whatsappPhone2+"?text="+defaultMessage+" "+window.location.href,
      '_blank',
    );

  } else {
    window.open(
      "https://wa.me/"+whatsAppPhone+"?text="+defaultMessage+" "+window.location.href,
      '_blank',
    );
  }
  // window.open(
  //   "https://wa.me/"+whatsAppPhone+"?text="+defaultMessage+" "+window.location.href,
  //   '_blank',
  // );
});

 

lazacode.org - Malaysia's programming knowledge sharing platform, where everyone can share their finding as reference to others.
...