H5怎么判断app是否已经安装过

编程入门 行业动态 更新时间:2024-10-06 10:39:10

H5怎么判断app是否<a href=https://www.elefans.com/category/jswz/34/1564368.html style=已经安装过"/>

H5怎么判断app是否已经安装过

H5中判断App是否安装过

  • 背景简介:
  • 代码详情

背景简介:

最近在处理H5的一些需求,其中有个小问题是需要在H5中判断是否安装过某个App:
如果安装过App,则打开App
如果未安装过App,则进入App的下载页面

代码详情

// 下面的代码,楼主楼主是在Vue2中使用的,如果语言不通,根据自己所写的语言稍微改下即可。
handleOpenApp() {
      const channel = this.channel
      const t = 1000
      const t1 = Date.now()
      const ifr = document.createElement('iframe')
      // 下面的this.url 是需要跳转到app的schema链接
      ifr.setAttribute('src', this.url)
      ifr.setAttribute('style', 'display:none')
      document.body.appendChild(ifr)
      setTimeout(function() {
      	// 启动app时间较长处理
        const t2 = Date.now()
        document.body.removeChild(ifr)
        if (t2 - t1 < t + 100) {
          console.log('hasApp', false)
          // 没有安装App,跳转到对应的App下载页面。
          // 下面的例子App下载页面也是H5页面。
          window.location.href = `${window.location.origin}/static/h5/index.html#/app/download?channel=${channel}`
        } else {
          console.log('hasApp', true)
          // 已经安装App,下面的this.url是需要跳转到app的schema链接。
          window.location.href = this.url
        }
      }, t)
    }

更多推荐

H5怎么判断app是否已经安装过

本文发布于:2023-08-03 10:42:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1287731.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:已经安装   app

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!