js调用exe文件 兼容所有浏览器

来源:互联网 发布:边缘融合软件 破解 编辑:程序博客网 时间:2024/06/04 19:54

1. 先注册URL PROTOCOL, 在windows 下就是注册表:

========================================================

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\myprotocol]
@="myprotocol Protocol"
"URL Protocol"=""

[HKEY_CLASSES_ROOT\myprotocol\DefaultIcon]
@="C:\\WINDOWS\\NOTEPAD.EXE"

[HKEY_CLASSES_ROOT\myprotocol\shell]
@=""

[HKEY_CLASSES_ROOT\myprotocol\shell\open]
@=""

[HKEY_CLASSES_ROOT\myprotocol\shell\open\command]
@="\"C:\\WINDOWS\\NOTEPAD.EXE\" "

======================================================

保存内容为 reg文件,然后执行,就加入注册表,注册了这个名字为myprotocol 的协议.

2. 写测试页面

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  </head>
    <body>
        <div>
            <a href="myprotocol://">
            执行可执行文件
            </a>
        </div>
    </body>
</html>


运行页面,点击链接,就能直接打开 notepad 。因为这里用的是写字板测试的,你可以在注册表中,改成其他任何你要的程序。


3.传参

Windows Registry Editor Version 5.00


[HKEY_CLASSES_ROOT\myprotocol]
@="myprotocol"
"URL Protocol"="D://CarTransfer.exe"


[HKEY_CLASSES_ROOT\myprotocol\DefaultIcon]
@="\"D:\\CarTransfer.exe" \"%1\""


[HKEY_CLASSES_ROOT\myprotocol\shell]
@=""


[HKEY_CLASSES_ROOT\myprotocol\shell\open]
@=""


[HKEY_CLASSES_ROOT\myprotocol\shell\open\command]
@="\"D:\\CarTransfer.exe\" \"%1\""



js部分

location.href="myprotocol://"+ sessionId +"&"+carsTransferId+"&"+carLicensePlate;



原创粉丝点击