百度分享如何自定义分享url和内容?

百度分享默认分享的是当前页的url,但也可以在同一个页面中分享多个不同的url,仅需进行如下简单的配置。

默认的代码如下:

<div id="bdshare" class="bdshare_t bds_tools get-codes-bdshare">

其实是有很多隐藏的参数的:

<div id="bdshare" class="bdshare_t bds_tools_32 get-codes-bdshare" data="{
'bdDes':'您的自定义分享摘要',  //'请参考自定义分享摘要'
'text':'您的自定义分享内容',  //'请参考自定义分享内容'
'title':'您的自定义pop窗口标题', //'请参考自定义pop窗口标题'
'pic':'您的自定义分享出去的图片', //'请参考自定义分享出去的图片'
'bdComment':'您的自定义分享评论', //'请参考自定义分享评论'
'url':'您的自定义分享url',  //'请参考自定义分享url',
'wbuid':'您的自定义微博 ID'
}">

如果想自定义url,只需要写如下代码即可,红色文字部分就是增加的url:

<!-- Baidu Button BEGIN -->
<div id="bdshare" class="bdshare_t bds_tools_32 get-codes-bdshare" data="{'url':'http://www.weste.net/index.html'}">
    <span class="bds_more">更多</span>
    <a class="bds_tsina">新浪</a>
    <a class="bds_tqq">腾讯</a>
    <a class="bds_renren">人人</a>
    <a class="bds_qzone">QQ </a>
</div>
<script type="text/javascript" id="bdshare_js" data="type=tools" ></script>
    <script type="text/javascript" id="bdshell_js"></script>
    <script type="text/javascript">
        document.getElementById("bdshell_js").src = "http://bdimg.share.baidu.com/static/js/shell_v2.js?cdnversion=" + Math.ceil(new Date()/3600000);
    </script>
<!-- Baidu Button END -->

参考资料:http://share.baidu.com/help/customization/config

转载于:https://www.cnblogs.com/kwishly/p/3441900.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
在小程序中,我们可以通过在页面中定义 `onShareAppMessage` 方法来自定义分享内容。 具体步骤如下: 1. 在需要分享的页面的 `.js` 文件中,定义 `onShareAppMessage` 方法: ```javascript Page({ onShareAppMessage: function () { return { title: '分享标题', path: '/pages/index/index', imageUrl: 'http://example.com/share.jpg' } } }) ``` 2. 在 `onShareAppMessage` 方法中,我们可以返回一个对象,该对象中包含以下参数: - `title`:分享标题,必填项。 - `path`:分享路径,必填项。 - `imageUrl`:分享图片地址,可选项。 3. 在 `onShareAppMessage` 方法中,我们可以通过调用微信提供的 API 获取当前页面的一些信息,例如页面标题、路径等。例如: ```javascript Page({ onShareAppMessage: function () { const title = this.data.title // 页面标题 const path = '/pages/index/index' // 页面路径 const imageUrl = 'http://example.com/share.jpg' // 分享图片地址 return { title: title, path: path, imageUrl: imageUrl } } }) ``` 4. 在 `.wxml` 文件中,我们可以添加一个分享按钮,并将其绑定到 `onShareAppMessage` 方法: ```html <button class="share-btn" bindtap="onShareTap">分享给好友</button> ``` ```javascript Page({ onShareTap: function () { wx.showShareMenu({ withShareTicket: true }) }, onShareAppMessage: function () { // ... } }) ``` 以上就是在微信小程序中通过 `onShareAppMessage` 方法自定义分享内容的方法。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值