码迷,mamicode.com
首页 > 微信 > 详细

JS 微信判断及分享参数修改

时间:2014-07-23 12:52:06      阅读:4522      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   color   width   io   

var iswechat = (window.navigator.userAgent.toLowerCase().match(/MicroMessenger/i) == ‘micromessenger‘);
var cloc = location.href.replace(/^#/, "").replace(/[^\/]*\.[^\/*]+$/, "");
var mainTitle = "",
    mainDesc = "",
    mainURL = cloc,
    mainImgUrl = cloc + "images/wechat_icon.jpg";

document.addEventListener(‘WeixinJSBridgeReady‘, function onBridgeReady() {
    iswechat = true;
    WeixinJSBridge.call(‘hideToolbar‘);
    onBridgeReady1();
});

function onBridgeReady1() {
    //转发朋友圈
    WeixinJSBridge.on("menu:share:timeline", function (e) {
        var data = {
            img_url: mainImgUrl,
            img_width: "120",
            img_height: "120",
            link: mainURL,
            //desc这个属性要加上,虽然不会显示,但是不加暂时会导致无法转发至朋友圈,
            desc: mainDesc,
            title: mainTitle
        };
        WeixinJSBridge.invoke("shareTimeline", data, function (res) {
            WeixinJSBridge.log(res.err_msg)
        });
    });
    //同步到微博
    WeixinJSBridge.on("menu:share:weibo", function () {
        WeixinJSBridge.invoke("shareWeibo", {
            "content": mainDesc,
            "url": mainURL
        }, function (res) {
            WeixinJSBridge.log(res.err_msg);
        });
    });
    //分享给朋友
    WeixinJSBridge.on(‘menu:share:appmessage‘, function (argv) {
        WeixinJSBridge.invoke("sendAppMessage", {
            img_url: mainImgUrl,
            img_width: "120",
            img_height: "120",
            link: mainURL,
            desc: mainDesc,
            title: mainTitle
        }, function (res) {
            WeixinJSBridge.log(res.err_msg)
        });
    });
};

JS 微信判断及分享参数修改,布布扣,bubuko.com

JS 微信判断及分享参数修改

标签:des   style   blog   color   width   io   

原文地址:http://www.cnblogs.com/allvie/p/3862546.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!