Skip to content

Instantly share code, notes, and snippets.

@camaleaun
Created October 30, 2020 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save camaleaun/be6c97f6a063ae6699ec6b14342d7e26 to your computer and use it in GitHub Desktop.
Save camaleaun/be6c97f6a063ae6699ec6b14342d7e26 to your computer and use it in GitHub Desktop.
WhatsApp link
function isMobileWA()
{
return (/Android|webOS|iPhone|iPad|iPod|Windows Phone|IEMobile|Mobile|BlackBerry/i.test(navigator.userAgent) );
}
var elm = jQuery('a[href*="whatsapp.com"]');
jQuery.each(elm, function(index, value){
var item = jQuery(value).attr('href');
if(item.indexOf('chat') != -1){
//nothing
} else if (item.indexOf('web.whatsapp') != -1 && isMobileWA()){
var itemLink = item;
var newLink = itemLink.replace('web.whatsapp', 'api.whatsapp');
jQuery(value).attr("href", newLink);
} else if (item.indexOf('api.whatsapp') != -1 && !isMobileWA()){
var itemLink = item;
var newLink = itemLink.replace('api.whatsapp', 'web.whatsapp');
jQuery(value).attr("href", newLink);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment