2016-07-27 90 views
0

我想通过链接发送一条消息到我的网站上的不同产品使用共享通过WhatsApp和短信在移动视图。我能够打开这两个应用程序并填充文本区域。
问题是我的链接包含两个参数,从&到最后的所有内容都没有填充到短信和WhatsApp的文本字段中。
这是我的代码 -
HTML -html - 使用共享通过whatsapp和短信发送多个参数链接

<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 -

$(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'); 
      }); 
     }); 

所需的输出是 -
嘿!看看这个mysite手表 - http://example.com/single.php?category=watches&pid=1234

当前输出 -
嘿!看看这个表上的mysite - http://example.com/single.php?category=watches

回答

0

你需要编码“&”对于这种“%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";