nciaer 发表于 2021-2-22 16:45:57

H5页面和小程序封装的H5来回跳转代码

            <div id = "nciaer" style = "text-align: center;">
                    <wx-open-launch-weapp id="launch-btn" username="gh_xxxxx" path="/pages/fuck/index">
                                <template><button style = "border-radius: 5px;padding: 8px 15px; background: #000;color: #FFF;border: none;margin: 10px 0;">点我</button></template>
                        </wx-open-launch-weapp>                   
            </div>
           
            <script>
            if(window.__wxjs_environment === 'miniprogram') {
                    $('#nciaer').html("<button style = \"border-radius: 5px;padding: 8px 15px; background: #000;color: #FFF;border: none;margin: 10px 0;\" onclick = \"wx.miniProgram.navigateTo({url: '/pages/fuck/index'})\">点我</button>");
            }
           
            </script>

效果就是在H5页面里,点击按钮可以打开小程序,这个小程序就是h5封装的,而且在小程序里点击按钮,还能跳转到小程序。

页: [1]
查看完整版本: H5页面和小程序封装的H5来回跳转代码