var btn = document.getElementById('launch-btn'); btn.addEventListener('launch', function (e) { console.log('success'); }); btn.addEventListener('error', function (e) { console.log('fail', e.detail); });
wx.ready(function () { var ua = navigator.userAgent.toLowerCase() var isWXWork = ua.match(/wxwork/i) == 'wxwork' var isWeixin = !isWXWork && ua.match(/micromessenger/i) == 'micromessenger'
if (isWeixin) {
wx.config({
//debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印
appId: 'ccccxxxx4354353453', // 必填,公众号的唯一标识
timestamp: 0123456, // 必填,生成签名的时间戳
nonceStr: 'aiyong1234', // 必填,填任意非空字符串即可
signature: 'aiyong1234', // 必填,填任意非空字符串即可
jsApiList: ['showOptionMenu', 'chooseImage', 'previewImage'], // 必填,随意一个接口即可
openTagList: ['wx-open-launch-weapp'], // 填入打开小程序的开放标签名
})
}
else {
alert("请在微信中打开");
}
})