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\" "
======================================================
保存內(nèi)容為 reg文件,然后執(zhí)行,就加入注冊表,注冊了這個名字為myprotocol 的協(xié)議.
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://">
執(zhí)行可執(zhí)行文件
</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;