Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to share image and text on whatsapp using javascript

Tags:

javascript

Hello till now i can share my content on whatsapp using javascript code but still not able to share image with text. Does anyone done it? Here is my javascript code:

$(document).ready(function() {
  $(document).on("click", '.mct_whatsapp_btn', function() {
    if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
      var text = $(this).attr("data-text");
      var url = $(this).attr("data-link");
      var message = encodeURIComponent(text) + " - " + encodeURIComponent(url);
      var whatsapp_url = "whatsapp://send?text=" + message;
      window.location.href = whatsapp_url;
    } else {
      alert("Please use an Mobile Device to Share this Article");
    }
  });
});
like image 471
shakti P Sisodiya Avatar asked Sep 11 '16 10:09

shakti P Sisodiya


People also ask

How send WhatsApp message in Javascript?

js) → We need to scan this QR from the WhatsAPPWeb from WhatsApp mobile app. var data = [{ id: 1, received: 'Hello', reply: 'Hi'},{ id: 2, received: 'Sorry', reply: 'No problem'},{ id: 3, received: 'Can we have a call? ', reply: 'Please leave a voicemail.

How can I redirect WhatsApp in HTML?

Use https://wa.me/<number> where the <number> is a full phone number in international format. Omit any brackets, dashes, plus signs, and leading zeros when adding the phone number in international format. Universal links can also include a pre-filled message that will automatically appear in the text field of a chat.

How open WhatsApp in Javascript?

If you have a website and want to open a WhatsApp chat with a pre-filled message, you can use our custom URL scheme to do so. Opening whatsapp://send?text= followed by the text to send, will open WhatsApp, allow the user to choose a contact, and pre-fill the input field with the specified text.

How do I send a photo automatically on WhatsApp?

To configure automatic photo, video or audio downloading, simply go to WhatsApp > tap More options > Settings > Storage and data > Media auto-download. Here you can choose when WhatsApp will automatically download media.


1 Answers

If you are trying to do this from browser then as per whatsapp docs, you can only send text or link through this. read it here : https://www.whatsapp.com/faq/en/iphone/23559013

If you want to send image with this whatsapp protocol, you can first upload image to your server and then use 'encodeURIComponent' to send link with this:

'whatsapp://send?text='+encodeURIComponent(imageURL)

As already pointed by @Akis, for using it in hybrid app framework like cordova/ionic, its better if you search for plugin to achieve this.

https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin

Above link with cordova plugin might help you in that.

like image 58
Rajendra Avatar answered Sep 20 '22 13:09

Rajendra