我一直在使用以下方式处理WhatsApp共享消息:
的WhatsApp-button.js
$_u.="Product Name:".$_productName."\n";
$_u.="Sku:".$_productSku."\n";
<a href="whatsapp://send" data-text="<?php echo nl2br($_u); ?>" data-href="" class="wa_btn <?php echo $buttonsize; ?>" style="display:none">Share</a>
如何添加换行符:
我尝试了\n
,\r\n
,PHP_EOL
和%0D%0A
,但它只显示为文字。
答案 0 :(得分:4)
如果您只想发送包含换行符的文本
use this %0a
link =`whatsapp://send?text=%0aHello%0aWorld`;
如果您要发送包含换行符的文本的某些网址链接
var encodedURL = encodeURIComponent(some_url);
link =`whatsapp://send?text=${encodedURL}%0aHello%0aWorld`;
现在将此链接嵌入锚标记中
<a href=link> Click here! </a>
答案 1 :(得分:3)
要在WhatsApp中创建换行符,可以使用此命令。它工作正常,我正在使用它:
use `%0a`
例如:
smsContain = "*Greetings from " + cname + " ,%0a %0aM/s. " + txtName.Text + " %0a %0aYour Bill for Advertisement is generated ; %0a %0aBill Date :- " + DateTime.ParseExact(dateTimePicker1.Text, "dd/MM/yyyy", null).ToString("dd/MM/yyyy") + " %0a %0aBill no :- " + lblBillNo.Text + " %0a %0aBilling Amount of Rs. " + lblNet_Amt.Text + " %0a %0aAdvertisement Published in " + news + " in " + Edi + " edition,%0a %0aReleased Date : " + DateTime.ParseExact(DateTime.Parse(dt).ToShortDateString(), "dd/MM/yyyy", null).ToString("dd/MM/yyyy") + ".%0a %0aPlease find the Bill attached below, and request you to please release the payment ASAP. %0a %0a %0aAny descripancy in regards to this Bill to reported to us immediately.%0a %0a %0aAlways at your Service....* ";
smsContain = smsContain.Replace("&", "+%26+");
答案 2 :(得分:1)
我有一个有效的解决方案:
HTML:
$_u.="Product Name:".$_productName."\n";
$_u.="Sku:".$_productSku."\n";
<a data-text="<?php echo $_u; ?>" data-link="" class="whatsapp">Share</a>
JS:
var isMobile = {
Android: function() {
return navigator.userAgent.match(/Android/i);
},
BlackBerry: function() {
return navigator.userAgent.match(/BlackBerry/i);
},
iOS: function() {
return navigator.userAgent.match(/iPhone|iPad|iPod/i);
},
Opera: function() {
return navigator.userAgent.match(/Opera Mini/i);
},
Windows: function() {
return navigator.userAgent.match(/IEMobile/i);
},
any: function() {
return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
}
};
$(document).on("click", '.whatsapp', function() {
if( isMobile.any() ) {
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 share this in mobile device");
}
});
答案 3 :(得分:0)
here中有一个基本上正在使用的解决方案:
whatsappMessage = window.encodeURIComponent(whatsappMessage)
答案 4 :(得分:0)