L O A D I N G
首页 / 前端 在 HTML5 页面中跳转到指定 App 的方法

在 HTML5 页面中跳转到指定 App 的方法

原创 分类: 前端 2025-2-3 23:47 阅读量:65
在 H5 页面中跳转到其他 APP,可以使用以下几种方式: URL Scheme(自定义协议) 许多 APP 都支持 URL Scheme 方式的跳转,例如: a href=weixin:// 打开微信 /a a href=alipa...

在 H5 页面中跳转到其他 APP,可以使用以下几种方式:

  1. URL Scheme(自定义协议)
    许多 APP 都支持 URL Scheme 方式的跳转,例如:

    <a href="weixin://">打开微信</a>
    <a href="alipay://">打开支付宝</a>
    <a href="yourapp://path">打开自定义 APP</a>

    注意:
    需要目标 APP 支持 URL Scheme,未安装 APP 时会无响应或报错。
    在 iOS 9+ 之后,需在 info.plist 中配置 LSApplicationQueriesSchemes。

  2. Universal Links(iOS)& Deep Link(Android)
    Universal Links(iOS)和 Deep Link(Android)可以更安全地跳转到 APP,且未安装时可跳转至 Web 页面。
    需要服务端配置特定文件(如 apple-app-site-association)。
    适用于 iOS 9+,不会弹出确认框,用户体验更好。
    示例:

    <a href="https://yourdomain.com/path">打开 APP</a>
  3. Intent Scheme(Android 专属)
    在 Android 设备上可以使用 intent:// 方案:

    <a href="intent://path#Intent;scheme=yourapp;package=com.example.app;end;">打开 APP</a>
  4. iframe 方式(部分浏览器支持)

    <iframe src="yourapp://path" style="display: none;"></iframe>
  5. 混合方式(兼容性方案)
    综合以上方法,推荐使用 JS 处理:

    
    <script>
    function openApp() {
    var schemeUrl = "yourapp://path";
    var storeUrl = "https://yourapp.com/download"; // APP 下载地址
    
    var ua = navigator.userAgent.toLowerCase();
    var isAndroid = ua.indexOf("android") > -1;
    var isIOS = ua.indexOf("iphone") > -1 || ua.indexOf("ipad") > -1;
    
    if (isIOS) {
      window.location.href = schemeUrl;
      setTimeout(() => {
        window.location.href = storeUrl;
      }, 2000);
    } else if (isAndroid) {
      window.location.href = schemeUrl;
      setTimeout(() => {
        window.location.href = storeUrl;
      }, 2000);
    } else {
      window.location.href = storeUrl;
    }
    }
    </script>

上一篇:2025【重庆联通】活动

下一篇:下一篇


扫描二维码,在手机上阅读