JS - use includes() for div or text replacement

0 votes
169 views
added Jan 12, 2022 in Javascript by lcjr First Warrant Officer (11,990 points)
$('#whatsappBtn').click(function(){
  var whatsAppPhone = '60123456789';
  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',
    );
  }
});

 

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