普通网址:如http://www.baidu.com
1 $(function(){ 2 /* 3 * htmls 当前页面的http://链接 4 */ 5 6 //请求验证签名 7 $.ajax({ 8 async:false, 9 type: "GET", 10 url: htmls, 11 dataType: "json", 12 success: function(data){ 13 14 appId = data.APPID; 15 time = data.timestamp; 16 signature = data.signature; 17 } 18 }); 19 20 21 wx.config({ 22 debug: false, 23 appId: appId, 24 timestamp: time, 25 nonceStr: 'Wm3WZYTPz0wzccnW', 26 signature: signature, 27 jsApiList: [ 28 'checkJsApi', 29 'onMenuShareTimeline', 30 'onMenuShareAppMessage', 31 'hideMenuItems', 32 'showMenuItems', 33 'hideAllNonBaseMenuItem', 34 'showAllNonBaseMenuItem', 35 'translateVoice', 36 'startRecord', 37 'stopRecord', 38 'onRecordEnd', 39 'playVoice', 40 'pauseVoice', 41 'stopVoice', 42 'uploadVoice', 43 'downloadVoice', 44 'chooseImage', 45 'previewImage', 46 'uploadImage', 47 'downloadImage', 48 'getNetworkType', 49 'openLocation', 50 'getLocation', 51 'hideOptionMenu', 52 'showOptionMenu', 53 'closeWindow', 54 'scanQRCode', 55 'chooseWXPay', 56 'openProductSpecificView', 57 'addCard', 58 'chooseCard', 59 'openCard' 60 ] 61 }); 62 63 wx.ready(function(){ 64 wx.hideAllNonBaseMenuItem();//隐藏所有菜单项 65 wx.showMenuItems({ 66 menuList: ["menuItem:exposeArticle","menuItem:share:appMessage","menuItem:share:timeline","menuItem:favorite",] // 要显示的菜单项,所有menu项见附录3 67 }); 68 69 wx.onMenuShareAppMessage({ 70 title: '测试', 71 desc: '测试描述', 72 link: 'http://www.baidu.com',//分享出去点进来时的链接 73 imgUrl: 'http://www.baidu.com/images/share_to_link.jpg',//分享出去展示的标题图片 74 type: '', 75 dataUrl:'', 76 success: function (res) { 77 alert('成功'); 78 } 79 80 }); 81 wx.onMenuShareTimeline({ 82 title: '测试发朋友圈标题', 83 link: 'http://www.baidu.com',//分享出去点进来时的链接 84 imgUrl: 'http://www.baidu.com/images/share_to_link.jpg',//分享出去展示的标题图片 85 success: function (res) { 86 alert('成功'); 87 } 88 }); 89 $('#close').click(function(){ 90 //关闭当前页面 91 wx.closeWindow(); 92 }) 93 94 }) 95 96 })
在普通网址下,这样控制菜单是可以控制住的,但是如果当前地址是http://www.baidu.com?id=1&name=测试&age=24,这时候就会发现菜单控制不住,目前的解决办法是将&连接符改成别的连接符,比如用-分割,“http://www.baidu.com?id=1-name=测试-age=24”,这样微信的菜单和分享就控制住了,具体原因待进一步验证
提示:如果发现右上角菜单死活控制不住的时候,不妨试试修改当前的url地址