我正在尝试通过移动视图中的whatsapp和sms使用共享发送带有指向我网站上不同产品的链接的消息。我可以打开这两个应用程序并填充文本区域
问题是我的链接包含两个参数,从&
到结尾的所有内容都没有在短信和whatsapp的文本字段中填充。
这是我的代码 -
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 -
$(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 :(得分:0)
你需要编码&#34;&amp;&#34;对于这个&#34;%26&#34; (http://www.w3schools.com/tags/ref_urlencode.asp)或任何您的语言UTF或其他,但仅适用于Twitter和WhatsApp,其他人理解&#34;&amp;&#34;:
var text = "Hey! Check out this "+name+" on mysite - http://example.com/single.php?pid="+id+"%26category=<?php echo $cat; ?>%26utm_campaign=Mobile";