h5打开微信小程序

<html>
    <body>
        <wx-open-launch-weapp
          id="launch-btn"
          username=""
          path="pages/index/index"
        >
            <template>
                <style>.btn { padding: 12px }</style>
                <button class="btn">打开小程序</button>
            </template>
        </wx-open-launch-weapp>
        <script src='https://res.wx.qq.com/open/js/jweixin-1.6.0.js'></script>
        <script>
            wx.config({
                debug: false,
                appId: '',
                timestamp: '',
                nonceStr: '',
                signature: '',
                jsApiList: [
                    'onMenuShareTimeline'
                ],
                openTagList: [
                    'wx-open-launch-weapp',
                    'wx-open-launch-app'
                ]
            });
            
            var btn = document.getElementById('launch-btn');
            btn.addEventListener('launch', function (e) {
                console.log('success');
            });
            btn.addEventListener('error', function (e) {
                console.log('fail', e.detail);
            });
            
            btn.click();
        </script>
    </body>
</html>

 

posted @ 2021-05-12 21:50  sojust  阅读(768)  评论(0编辑  收藏  举报