百度官方网站的分享是不支持https的,解决方案是: https://github.com/hrwhisper/baiduShare
pc端分享是,存在一个问题,就是微信分享的链接问题,一般我们pc和手机都是分开的,而我们希望微信分享能够分享扫码到手机端,这个文档中有提到:
onBeforeClick | function | function(cmd,config){} | 在用户点击分享按钮时执行代码,更改配置。 cmd为分享目标id,config为当前设置,返回值为更新后的设置。 |
onAfterClick | function | function(cmd){} | 在用户点击分享按钮后执行代码,cmd为分享目标id。可用于统计等。 |
所以可以使用before改变微信分享的链接
<script>
window._bd_share_config = {
common : {
bdText : '<%= @article.title %>',
bdDesc : '<%= @article.meta_description.blank? ? @article.title : @article.meta_description %>',
bdUrl : '<%= @url %>',
bdPic : '<%= oss_image_url @article.image %>',
onBeforeClick: function(id, config) {
if (id == 'weixin') {
config.bdUrl = "<%= @mobile_url %>";
return config;
}
}
},
share : [{
"bdSize" : 50
}]
}
with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='https://www.xxx.com/bdshare/api/js/share.js?cdnversion='+~(-new Date()/36e5)];
</script>