• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

js打开客户端程序和文件并传递参数

武飞扬头像
@糖糖
帮助1

js调用本地exe程序:
学新通
学新通
实现
一.新建txt文件,复制下面代码 自定义协议universalLinks(可修改)

Windows Registry Editor Version 5.00
 
[HKEY_CLASSES_ROOT\universalLinks]
@="universalLinks Protocol"
"URL Protocol"= ""
 
[HKEY_CLASSES_ROOT\universalLinks\DefaultIcon]
@="D:\\QMDownload\\SoftMgr\\HBuilderX.2.7.14.20200618.full\\HBuilderX\\HBuilderX.exe"
 
[HKEY_CLASSES_ROOT\universalLinks\shell]
@= ""
 
[HKEY_CLASSES_ROOT\universalLinks\shell\open]
@= ""
 
[HKEY_CLASSES_ROOT\universalLinks\shell\open\command]
@="\"D:\\QMDownload\\SoftMgr\\HBuilderX.2.7.14.20200618.full\\HBuilderX\\HBuilderX.exe\" \"%1\""
学新通

修改:

  1. 修改txt文件里的路径(注意:斜杠要用双斜杠)
    红色部分为调用程序exe的文件路径
    绿色部分为固定写法
    学新通
  2. 保存txt文件,并修改为xxx.reg文件。最后双击运行
    学新通

二.js 调用协议

// 一键打开应用程序
        open_miniapp() {
            console.log(navigator.userAgent)
            // 检测用户的设备是否是Windows系统
            if (/windows|win32/i.test(navigator.userAgent)) {
                // 检测用户的浏览器是否能使用universalLink
                let openApp = false;
                let userAgent = navigator.userAgent
                //判断是否 Firefox浏览器
                if (userAgent.indexOf("Firefox") > -1) {
                    openApp = true;
                }
                //判断是否 Chrome浏览器
                if (userAgent.indexOf("Chrome") > -1) {
                    openApp = true;
                }
                //判断是否 Edge浏览器
                if (userAgent.indexOf("Edg") > -1) {
                    openApp = true;
                }
                if (openApp) {
                    try {
                        window.location.href = "universalLinks://test.mcdx";
                    } catch (err) {
                        console.log(err)
                        this.$message.warning("出错了,请手动打开小程序!")
                    }
                } else {
                    this.$message.warning("您的浏览器不支持自动打开小程序,请手动打开小程序!")
                    this.$notify.warning({
                        title: "提示",
                        content: "推荐使用Chrome浏览器!",
                        placement: "bottom-right",
                        duration: 3000
                    })
                }
            } else {
                this.$message.warning("您的设备暂不支持运行小程序,请在Windows电脑上进行操作!")
            }
        },
学新通

window.location.href = “universalLinks://test.mcdx”; test.mcdx为传递的参数 (需要编写exe文件来接受参数,客户需要安装这个exe文件)

这篇好文章是转载于:编程之路

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 编程之路
  • 本文地址: /boutique/detail/tanhghaeca
系列文章
更多 icon
同类精品
更多 icon
继续加载