前端检测 pc端是否安装exe 应用,有直接通过url唤起打开应用,无下载处理

1 安装唤起 插件"protocolcheck": "1.0.0", (当前前端项目vue3 , node  v8.0+)

npm i  protocolcheck@1.0.0 --save

2 页面引入使用

// 1 引入
import protocolCheck from 'protocolcheck'

// 2 使用
// 打开客户端
const urls = reactive({
    clientCallCmd: '' // 应用链接
})
function openClientHanle() {
  protocolCheck(urls.clientCallCmd, (fail: any) => {
    // 1 失败回调
    ElMessageBox.confirm('并未检测到启动器,是否下载?', '提示', {
      confirmButtonText: '下载',
      cancelButtonText: '取消',
      type: 'warning'
    })
      .then(async () => {
        // downloadStarter()
        // 去下载
      })
      .catch(() => {})
  }),
    (success: any) => {
      // 2 成功回调 直接唤起
      console.log('🚀 ~ openClientHanle ~ success:', success)
    }
}

方法二,通过github  搜索引入 js 包使用

1 自定义方法protocolcheck.js

function _registerEvent(target, eventType, cb) {
  if (target.addEventListener) {
    target.addEventListener(eventType, cb)
    return {
      remove: function () {
        target.removeEventListener(eventType, cb)
      }
    }
  } else {
    target.attachEvent(eventType, cb)
    return {
      remove: function () {
        target.detachEvent(eventType, cb)
      }
    }
  }
}

export function openUriWithTimeoutEXE(uri, fail_c, success_c) {
  var timeout = setTimeout(function () {
    // 延时失败回调
    fail_c()
    handler.remove()
  }, 1500)

  //处理iframe中运行的页面(blur必须在顶级窗口中注册)
  var target = window
  while (target != target.parent) {
    target = target.parent
  }
  function onBlur() {
    // 唤起应用清除fail
    clearTimeout(timeout)
    handler.remove()
    success_c()
  }
  var handler = _registerEvent(target, 'blur', onBlur)
  window.location = uri
}

引入使用


import { openUriWithTimeoutEXE } from './protocolcheck.js'

// 打开客户端唤起exe 检查
function openClient() {
  openUriWithTimeoutEXE(
    urls.clientCallCmd,
    (fail: any) => {
      console.log('🚀 ~ protocolCheck ~ fail:', fail)
      ElMessageBox.confirm(t('并未检测到启动器,是否下载?'), t('common.reminder'), {
        confirmButtonText: '下载',
        cancelButtonText: t('common.cancel'),
        type: 'warning'
      })
        .then(async () => {
          downloadStarter()
        })
        .catch(() => {})
    },
    (success: any) => {
      console.log('🚀 ~ openClient ~ success:', success, 9999)
      // urls.clientCallCmd && (window.location.href = urls.clientCallCmd)
    }
  )
}

  • 3
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值