在微信浏览器中无法触发WeixinJSBridgeReady事件,导致了本人自定义分享的内容失效,代码如下:
var linkUrl = "http://www.XXXXXXXX.cn/index.aspx"; var descMsg = "XXXXXXXXXXXXXXXXX"; var titleMsg = "XXXX"; document.addEventListener("WeixinJSBridgeReady", function onBridgeReady() { // 通过下面这个API隐藏右上角按钮 //WeixinJSBridge.call("hideOptionMenu"); // 发送给好友 WeixinJSBridge.on("menu:share:appmessage", function (argv) { WeixinJSBridge.invoke("sendAppMessage", { "img_url": "http://xxxx/sharelogo.png", "img_width": "160", "img_height": "160", "link": linkUrl, "desc": descMsg, "title": titleMsg }, function (res) { if (res.err_desc == "已确认分享") { //分享成功 } }) }); // 分享到朋友圈 WeixinJSBridge.on("menu:share:timeline", function (argv) { WeixinJSBridge.invoke("shareTimeline", { "img_url": "http://xxxx/sharelogo.png", "img_width": "160", "img_height": "160", "link": linkUrl, "title": descMsg, "desc": descMsg }, function (res) { if (res.err_msg == "share_timeline:ok") { //分享成功 } }); }); }, false)
解决方案