简体   繁体   English

html-通过whatsapp和sms使用共享发送具有多个参数的链接

[英]html - send link with multiple parameter using share via whatsapp and sms

I am trying to send a message with a link to different products on my site using share via whatsapp and sms in mobile view. 我正在尝试通过移动视图中的whatsapp和sms发送一条消息,其中包含指向我网站上不同产品的链接。 I am able to open both the apps and populate the text area. 我能够同时打开两个应用程序并填充文本区域。
The problem is that my link contains two parameters and everything from & till the end doesn't get populated in the text field for both sms and whatsapp. 问题是我的链接包含两个参数,并且从&直到结尾的所有内容都不会在短信和whatsapp的文本字段中填充。
This is my code - 这是我的代码-
HTML - HTML-

<div class="form-group mshare">
    <a id="wshare" class="btn btn-default btn-block" data-action="share/whatsapp/share">
        <i class="fa fa-whatsapp"></i> Whatsapp
    </a>
</div>
<div class="form-group mshare">
    <a id="sshare" class="btn btn-default btn-block">
        <i class="fa fa-envelope-o"></i> SMS
    </a>
</div>

Javascript - Javascript-

$(document).ready(function(){
            $(document).on("click","#wshare",function(){
                var id = $('#shprodid').val();
                var name = $('#shprodnm').val();
                var text = "Hey! Check out this "+name+" on mysite - http://example.com/single.php?pid="+id+"&category=<?php echo $cat; ?>";
                alert(text);
                $(this).attr("href","whatsapp://send?text="+text);
            });
         });

        $(document).ready(function(){
            $(document).on("click","#sshare",function(){
                var id = $('#shprodid').val();
                var name = $('#shprodnm').val();
                var text = "Hey! Check out this "+name+" on mysite - http://example.com/single.php?category=<?php echo $cat; ?>&pid="+id;
                $(this).attr("href","sms:?body="+text);
                alert('clicked');
            });
         });

The desired output is - 所需的输出是-
Hey! 嘿! Check out this watch on mysite - http://example.com/single.php?category=watches&pid=1234 在mysite上查看此手表-http: //example.com/single.php? category=watches&pid=1234

The current output - 当前输出-
Hey! 嘿! Check out this watch on mysite - http://example.com/single.php?category=watches 在mysite上查看此手表-http: //example.com/single.php? category=watches

您需要为此“%26”( http://www.w3schools.com/tags/ref_urlencode.asp )或其他任何语言(对于您的语言UTF或其他语言)进行编码,但仅对Twitter和WhatsApp进行编码,其他人才能理解“&” :

var text = "Hey! Check out this "+name+" on mysite - http://example.com/single.php?pid="+id+"%26category=<?php echo $cat; ?>%26utm_campaign=Mobile";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM