console.log(document.location.href);//本页面地址 function shareTo(stype) { var ftit = ''; var flink = ''; var lk = ''; //获取文章标题 ftit = $('.article h1').text();//此处的class名应该根据自己本身页面的class来取 //获取网页中内容的第一张图片 flink = 'https://' + window.location.host + $('.content img').eq(0).attr('src'); if (typeof flink == 'undefined') { flink = ''; } //当内容中没有图片时,设置分享图片为网站logo if (flink == '') { /** * 此处根据自己页面的样式以及布局进行改变处理 */ lk = 'https://' + window.location.host + '../../new/image/logo308.png'; } //如果是上传的图片则进行绝对路径拼接 if (flink.indexOf('/uploads/') != -1) { lk = 'http://' + window.location.host + flink; } //百度编辑器自带图片获取 if (flink.indexOf('ueditor') != -1) { lk = flink; } /* * 进行QQ分享测试时,本地的页面会分享报错,需要用部署地址 */ //qq空间接口的传参 if (stype == 'qzone') { window.open('https://sns.qzone.qq.com/cgi-bin/qzshare/cgi_qzshare_onekey?url=' + document.location.href + '?sharesource=qzone&title=' + ftit + '&pics=' + lk + '&summary=' + document.querySelector('meta[name="description"]').getAttribute('content')); } //新浪微博接口的传参 if (stype == 'sina') { window.open('http://service.weibo.com/share/share.php?url=' + document.location.href + '?sharesource=weibo&title=' + ftit + '&pic=' + lk + '&appkey=2706825840'); } //qq好友接口的传参 if (stype == 'qq') { //获取meta标签的值,然后分享 window.open('http://connect.qq.com/widget/shareqq/index.html?url=' + document.location.href + '?sharesource=qzone&title=' + ftit + '&pics=' + lk + '&summary=' + document.querySelector('meta[name="description"]').getAttribute('content') + '&desc=' + document.querySelector('meta[name="description"]').getAttribute('content')); } //生成二维码给微信扫描分享 if (stype == 'wechat') { var qrstr = document.location.href; if ($('#qrid')[0].innerHTML == "") { $('#qrid').qrcode(qrstr); } $('.qrid_zz')[0].style.display = "block"; } } $('.qrid_zz').click(function () { $('.qrid_zz')[0].style.display = "none"; })