完整的官方文檔在此:javascript
https://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.htmlhtml
之前有些第三方開發的js庫,確定是不要再用了。前端
|
wx.config({ debug: false, appId: '1111111111111',// 必填,公衆號的惟一標識 timestamp: timestamp,// 必填,生成簽名的時間戳 nonceStr: nonce,// 必填,生成簽名的隨機串 signature: signature,// 必填,簽名, jsApiList: [ 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareWeibo', 'onMenuShareQZone' ]}); wx.error(function(res){ console.log('出現一個問題:'+res.errorMessage); }); wx.ready(function(){ console.log('wx準備就緒'); } var shareConfig = { title: title, // 分享標題 desc: descr, // 分享描述 link: curl, imgUrl: image, // 分享圖標 type: 'link', // 分享類型,music、video或link,不填默認爲link success: function () { console.log('onMenuShareAppMessage ok'); }, cancel: function () { console.log('onMenuShareAppMessage cancel'); } }; wx.onMenuShareAppMessage(shareConfig);
config, ready, onMenuShareAppMessage幾個屬性順序設置,其實這是有問題的,特別是在手機端,執行比較慢的時候,極可能onMenuShareAppMessage已經設置了, wx.ready尚未被執行,這時設置就失敗了,並且沒有任何錯誤信息。正確的作法是把onMenuShareAppMessage調用放在ready方法裏面:git
var shareConfig = { title: title, // 分享標題 desc: descr, // 分享描述 link: curl, imgUrl: image, // 分享圖標 type: 'link', // 分享類型,music、video或link,不填默認爲link success: function () { console.log('onMenuShareAppMessage ok'); }, cancel: function () { console.log('onMenuShareAppMessage cancel'); } }; wx.onMenuShareAppMessage(shareConfig);
iframe.onload = function(){ console.log("iframe load!"); if(browser.versions.weixin){ shareConfig(iframe.contentWindow.document.title ,iframe.contentWindow.document.title ,iframe.contentDocument.getElementById('share_img_url').innerHTML ); } };