链接跳转小程序

该博客介绍了一个HTML页面,其JavaScript代码会在加载完成后尝试通过scheme打开微信小程序。如果失败,2秒后会显示一个按钮供用户手动点击打开。源代码可在Gitee和GitHub上找到。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="Expires" content="0">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-control" content="no-cache">
    <meta http-equiv="Cache" content="no-cache">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="shortcut icon" type="image/x-icon" href="https://res.wx.qq.com/a/wx_fed/assets/res/NTI4MWU5.ico">
    <title>确认打开微信小程序</title>
</head>

<body>
    <div id="jumpToMicroAPP">
        <!-- js生成按钮 -->
    </div>
    <div>
        <a href="https://gitee.com/zhaoquan/sms-jump-to-microapp">Gitee</a>
        <a href="https://github.com/zhaoquan/smsjumptomicroapp">GitHub</a>
    </div>
</body>

<script>
    // 用js实现在加载完成一个页面后自动执行一个方法
    window.onload = async function () {
        //微信小程序 Url Scheme 可以到mp.weixin.qq.com 小程序后台右上角,工具下生成,另外也可以通过接口生成
        let scheme = "weixin://dl/business/?t=8ixV32RuXKf" // 需要打开的app scheme 地址

        // 尝试打开 scheme
        window.location.href = scheme;

        // 2秒后显示按钮
        let downloadTimer = setTimeout(function () {
            let html = `<button class="btn" id="openBtn" onclick="openWithApp()">点击打开微信小程序</button>`
            document.getElementById('jumpToMicroAPP').innerHTML = html;
        }, 2000);
    }
</script>

<script>
    // 参考链接:https://blog.youkuaiyun.com/weixin_42895400/article/details/87799262
    function openWithApp(id) {
        //微信小程序 Url Scheme 可以到mp.weixin.qq.com 小程序后台右上角,工具下生成,另外也可以通过接口生成
        let scheme = "weixin://dl/business/?t=8ixV32RuXKf" // 需要打开的app scheme 地址

        // 尝试打开 scheme
        window.location.href = scheme;
    }
</script>
<style type="text/css">
    .btn {
        display: inline-block;
        position: fixed;
        padding: 15px 32px;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        background-color: #27ae60;
        box-shadow: 0 8px 16px 0 rgba(0, 0, 0, 0.2), 0 6px 20px 0 rgba(0, 0, 0, 0.19);
        border: none;

        color: white;
        font-size: 18px;
        font-weight: 600;
        text-align: center;
        text-decoration: none;
    }
</style>

</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值