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)
    }

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

  • 相关阅读:
    spring boot 2.1学习笔记【五】SpringBootTest单元测试及日志
    Java网络编程-UDP
    Java网络编程-TCP
    String的特性
    内存池的使用
    软件定时器的使用
    邮箱
    事件集
    线程优先级翻转
    临界区,互斥量与信号量
  • 原文地址:https://www.cnblogs.com/busicu/p/5120675.html
Copyright © 2011-2022 走看看