你好,到目前为止,我可以使用 javascript 代码在 Whatsapp 上分享我的内容,但仍然无法分享带有文本的图像。有人做过吗?这是我的 JavaScript 代码:
$(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");
}
});
});
如果您尝试从浏览器执行此操作,则根据 Whatsapp 文档,您只能通过此发送文本或链接。在这里阅读:https://www.whatsapp.com/faq/en/iphone/23559013 https://www.whatsapp.com/faq/en/iphone/23559013
如果您想使用此 Whatsapp 协议发送图像,您可以首先将图像上传到您的服务器,然后使用“encodeURIComponent”发送链接:
'whatsapp://send?text='+encodeURIComponent(imageURL)
正如@Akis 已经指出的那样,为了在 cordova/ionic 等混合应用程序框架中使用它,如果您搜索插件来实现这一点,那就更好了。
https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin
上面的 cordova 插件链接可能会帮助你。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)