Reputation: 137
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");
}
});
});
Upvotes: 8
Views: 29693
Reputation: 1434
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.
Upvotes: 6