zoukankan      html  css  js  c++  java
  • 分享

    /*分享模块,使用百度分享*/
    function shareFn(json){
    this.weixinUrl = "http://res.wx.qq.com/open/js/jweixin-1.0.0.js";
    this.baiduUrl="http://bdimg.share.baidu.com/static/api/js/share.js";
    this.ua = navigator.userAgent.toLowerCase();
    this.config={
    title :json.title, // 分享标题
    desc :json.desc, // 分享链接
    link :json.link, // 分享链接
    imgUrl :json.imgUrl, // 分享图标
    }

    //初始化方法
    this.init();
    };


    shareFn.prototype.init=function(){
    var _this=this;
    if (this.isWeixin()){
    var oScript = document.createElement("script");
    oScript.setAttribute("src",this.weixinUrl);
    document.getElementsByTagName("head")[0].appendChild(oScript);
    wx.ready(function(){
    wx.onMenuShareAppMessage(_this.config);
    wx.onMenuShareTimeline(_this.config);
    wx.onMenuShareQQ(_this.config);
    wx.onMenuShareWeibo(_this.config);
    wx.onMenuShareQZone(_this.config);
    });
    } else {
    var oScript = document.createElement("script");
    oScript.setAttribute("src",this.baiduUrl);
    document.getElementsByTagName("head")[0].appendChild(oScript);

    window._bd_share_config = {
    common : {
    bdText: _this.config.title,
    bdDesc: _this.config.desc,
    bdUrl : _this.config.link,
    bdPic : _this.config.imgUrl
    },
    share : [{
    "bdSize" : 32
    }]
    }


    }
    }

    shareFn.prototype.isWeixin = function() {
    return this.ua.match(/MicroMessenger/i) == "micromessenger";
    }


    function share(json){
    return new shareFn(json)
    }

    支持微信分享和浏览器分享

  • 相关阅读:
    Android_Spinner_example
    23.pyspider安装
    22.Windows及linux下gerapy使用
    21.scrapy爬虫部署
    12.利用kakatips对网站数据信息监控
    11.启信宝数据二次筛选解密(字符串的分割与拼接及正则匹配)-2
    10.Ubuntu操作系统及python2.7、3.5 exe
    9.数据库多表一起查询
    8.代理ip使用
    7.阿布云代理服务器试用
  • 原文地址:https://www.cnblogs.com/busicu/p/5120675.html
Copyright © 2011-2022 走看看