Are you first timer at lazacode.org? Why not join us and start exchange your programming knowledge with everyone. Register today!

JS - use includes() for div or text replacement

0 votes
5 views
added 5 days ago in Javascript by lcjr Second Warrant Officer (6,570 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',
    );
  }
});

 

Please log in or register to response this reference.

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