在页面上有个列表页需要添加分享按钮,如图
使用百度分享,点击下一页重新加载页面不显示分享按钮。原因是因为需要重新加载一下init()方法。
html = '<div class="shore-circle pull-right">' +
'<span class="mr5">分享</span>' +
'<div class="bdsharebuttonbox">' +
'<a href="#" class="bds_copy" data-cmd="copy" title="分享到复制网址" data-id="'+ id +'" data-title="'+ name +'"></a>' +
'<a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信" data-id="'+ id +'" data-title="'+ name +'"></a>' +
'<a href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博" data-id="'+ id +'" data-title="'+ name +'"></a>' +
'<a href="#" class="bds_sqq" data-cmd="sqq" title="分享到QQ好友" data-id="'+ id +'" data-title="'+ name +'"></a><div>' +
'<i class="iconfont icon-date"></i>' + createDate + '<span></span><i ' +
'class="iconfont icon-look"></i>' + views + '阅读</div></div></li>';
var shareId = "";
var title = "";
$(".bdsharebuttonbox a").mouseover(function () {
shareId = $(this).attr("data-id");
title = $(this).attr("data-title");
});
window._bd_share_config = {
"common": {
"bdSnsKey": {},
"bdText": "",
"bdMini": "1",
"bdMiniList": false,
"bdPic": "",
"bdStyle": "1",
"bdSize": "16",
"onBeforeClick": beforeShareClick
},
"share": {}
};
with (document) 0[(getElementsByTagName('head')[0] || body).appendChild(createElement('script')).src = 'http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion=' + ~(-new Date() / 36e5)];
if (window._bd_share_main) {
window._bd_share_main.init()
}
function beforeShareClick(cmd, config) {
//设置 config
if (shareId) {
config.bdText = title;
config.bdUrl = window.location.protocol + "//" + document.domain + "/zx/detail?id=" + shareId
}
return config;
}