技术文章分类(180)

技术随笔(11)

WeixinJSBridge share(微信自定义分享内容)

1、WeixinJSBridge share(微信自定义分享内容)

可以自定义分享内容。(在右上角的分享)

 

<!DOCTYPE html>
<html lang="zh-CN"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <meta name="format-detection" content="telephone=no">
    <title>智能点菜</title>
</head>
<body>
<script>
    document.addEventListener("WeixinJSBridgeReady",function(){
        weixinJSBgReadyEventSet();
    }) ;

    function weixinJSBgReadyEventSet(){
        var appid="";//经常设置为''
        var title = "title";
        var link = "http://www.baidu.com";
        var desc = "desc";
        var img_url = "http://dongway.com.cn/resources/front/new/images/logo.png";
        var img_width = "120";//好像设置成其他也没用
        var img_height = "120";
        share(appid,title,link,desc,img_url,img_width,img_height,'menu:share:timeline','shareTimeline');//timeline:分享至朋友圈
        share(appid,title,link,desc,img_url,img_width,img_height,'menu:share:appmessage','sendAppMessage');//appmessage分享至微信好友
    }

    function share(appid,title,link,desc,img_url,img_width,img_height,button,event) {
        if (typeof WeixinJSBridge == "undefined") {
            alert("请先通过微信分享文章 ");
        } else if (typeof window.WeixinJSBridge.invoke == 'undefined'){
            alert("invoke!");
        }
        else {
            WeixinJSBridge.on(button, function(argv){
                WeixinJSBridge.invoke(event,{
                    "appid":appid,             //设置为null
                    "title": title,
                    "link": link,
                    "desc": desc,
                    "img_url": img_url,
                    "img_width":img_width,                            //图片宽度
                    "img_height":img_height                            //图片高度
                }, function(d) {
                    //alert(d.err_msg);//这里是分享功能的回调函数,有错误的时候有用
                });
            });
        }
    }
</script>
</body></html>

 

posted @ 2014-05-26 09:29  坤哥MartinLi  阅读(3982)  评论(0编辑  收藏  举报