html 在WhatsApp消息中创建换行符

1bqhqjot  于 2022-12-02  发布在  其他
关注(0)|答案(6)|浏览(339)

我一直在使用WhatsApp分享消息:

whatsap-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\nPHP_EOL%0D%0A,但它只显示为文本。

ruarlubt

ruarlubt1#

如果要发送一个只包含换行符的文本

use this %0a

link =`whatsapp://send?text=%0a‎Hello%0aWorld`;

如果你想发送一些url链接,文本中包含换行符

var encodedURL = encodeURIComponent(some_url);
link =`whatsapp://send?text=${encodedURL}%0a‎Hello%0aWorld`;

现在将此链接嵌入到锚标记中

<a href=link> Click here! </a>
1cosmwyk

1cosmwyk2#

要在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+");
8ftvxx2r

8ftvxx2r4#

我有一个可行的解决方案:
于飞:

$_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");
                    }

                });
7fyelxc5

7fyelxc55#

这里有一个解决方案,基本上是使用:

whatsappMessage = window.encodeURIComponent(whatsappMessage)
hs1rzwqc

hs1rzwqc6#

尝试使用&#13;。这是一个特殊的HTML代码。
例如:
你好!你今天好吗?
会得到这样的结果:
你好啊!
你今天好吗?

相关问题