• 百度分享


    最近发现用百度分享很方便,他集合了新浪微博、qq空间等分享

     1 //输出到网页中的html代码
     2 function GetShareHtml_v2() {
     3     var html = '<div data-tag="share_1" class="bdsharebuttonbox ">';
     4     html += '<a data-cmd="tsina" class="bds_tsina" title="分享到新浪微博"></a>';
     5     html += '<a data-cmd="weixin" class="bds_weixin" title="分享到微信"></a>';
     6     html += '<a data-cmd="mshare" class="bds_mshare" title="分享到一键分享"></a>';
     7     html += '<a class="bds_qzone" data-cmd="qzone" title="分享到QQ空间"></a>';
     8     html += '<a data-cmd="renren" class="bds_renren" title="分享到人人网"></a>';
     9     html += '<a data-cmd="tqq" class="bds_tqq" title="分享到腾讯微博"></a>';
    10     html += '<a data-cmd="more" class="bds_more"></a>';
    11     html += '</div>';
    12     return html;
    13 }
    14 //输出到网页中简短的html代码
    15 function GetShareHtml_short() {
    16     var html = '<div data-tag="share_1" class="bdsharebuttonbox ">';
    17     html += '<a data-cmd="more" class="bds_more">分享到</a>';
    18    html += '</div>';
    19     return html;
    20 }
    21 
    22 //配置
    23 window._bd_share_config = {
    24     common: {
    25         bdText:'', //自定义分享内容
    26         bdDesc: '',//自定义分享摘要
    27         bdUrl:window.location.href,//自定义分享url地址
    28         bdPic:'' //自定义分享图片
    29     },
    30     share: [{//按钮分享
    31         "tag":"share_1",
    32         "bdSize": 16
    33     }]
    34 
    35 }
    36 with (document) 0[(getElementsByTagName('head')[0] || body).appendChild(createElement('script')).src = 'http://bdimg.share.baidu.com/static/api/js/share.js?cdnversion=' + ~(-new Date() / 36e5)];
    js代码

    使用说明
    第一步:分享对象属性重新赋值
    第二步:把代码输出到指定的地方中
    第三步:引用分享js,必须放在分享对象属性重新赋值的前面
    代码如下:
    <script src="/Content/Scripts/Share.js" type="text/javascript"></script>
    <script type="text/javascript">
    //分享对象属性重新赋值
    var winCommon=window._bd_share_config.common;
    winCommon.bdText = "dfsdfs"; //自定义分享内容
    winCommon.bdPic = "2222222"; //自定义分享图片
    winCommon.bdUrl = "2222222"; //自定义分享Url
    $(function () {
    $("#share1").html(GetShareHtml_v2()); //把代码输出到Id为share1的div中
    $("#share1").html(GetShareHtml_short()); //如果只显示’分享到‘ 则调用GetShareHtml_short()
    });

    </script>

  • 相关阅读:
    根据不同的窗口尺寸来选择不同的样式
    用JavaScript检测视频格式支持
    用JavaScript检测音频格式支持
    C#取整函数Math.Round、Math.Ceiling和Math.Floor
    asp.net在同一页面跳转到指定位置
    对存储过程进行加密和解密
    各种SQL语句
    centos7.2安装nginx
    springboot利用mock进行junit单元测试,测试controller
    centos7环境搭建一台mysql服务器启动多个端口
  • 原文地址:https://www.cnblogs.com/nik2011/p/3816612.html
Copyright © 2020-2023  润新知