新浪微博、QQ空间、QQ好友、微信分享javascript代码
点击分享至微信、空间、QQ和微信的javascript代码。
HTML代码部分:
<ul> <li class="wb"> <a href="javascript:void(0);" onclick="shareUrl('weibo');">微博</a> </li> <li class="qz"> <a href="javascript:void(0);" onclick="shareUrl('qzone');">QQ空间</a> </li> <li class="wx"> <a href="javascript:void(0);">微信</a> <div class="qrcode"> <div id="qrcode"></div> <div class="text"> <p>用微信扫码二维码</p> <p>分享至好友和朋友圈</p> </div> </div> </li> <li class="qq"> <a href="javascript:void(0);" onclick="shareUrl('qq');">QQ</a> </li> </ul>
javascript代码部分:
function shareUrl(social){ var _title = encodeURIComponent(document.title); var _url = document.location; var _pic = document.getElementsByTagName('img')[0].src; if(social == 'qzone'){ var _shareUrl = 'https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=' + _url + '&title=' + _title + '&pics=' + _pic + '&summary=&desc='; }else if(social == 'weibo'){ var _shareUrl = 'https://service.weibo.com/share/share.php?url=' + _url + '&title=' + _title + '&pic=' + _pic; }else if(social == 'qq'){ var _shareUrl = 'https://connect.qq.com/widget/shareqq/index.html?url=' + _url +'&title=' + _title + '&pics=' + _pic + '&summary=&desc='; } window.open(_shareUrl,'_blank'); }
其中当前页面二维码图片可以借助jquery插件jquery.qrcode生成,插件自行搜索下载,调用代码如下:
<script type="text/javascript" src="js/jquery.qrcode.min.js"></script> <script type="text/javascript"> $(function(){ $('#qrcode').qrcode('http://www.neirong.org'); }); </script>
<< 上一篇
下一篇 >>