一、思路
如果想要web調用本地應用程序,可以通過自定義URL Protocol來調用應用程序。
瀏覽器在解析到自定義URL Protocol之后,會尋找注冊表,然后通過注冊表啟動相應的程序。這樣就可以在WEB頁面調到你的程序了。比如在瀏覽器地址欄輸入“tencent://message/?uin=88888888&Site=JooIT.com&Menu=yes”就會出現一個QQ對話框。
二、實現
1、新建.reg文件,並運行
Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\注冊表名] "URL Protocol"="程序路徑" @="注冊表名Protocol" [HKEY_CLASSES_ROOT\注冊表名\DefaultIcon] @="程序路徑,1" [HKEY_CLASSES_ROOT\注冊表名\shell] [HKEY_CLASSES_ROOT\注冊表名\shell\open] [HKEY_CLASSES_ROOT\注冊表名\shell\open\command] @="\"程序路徑\" \"%1\""
其中,@="\"程序路徑\" \"%1\"",此處的%1表示傳入的參數,比如:tencent://message,解析后就可以得到參數message。
保存為.reg文件並運行。
2、web頁面調用
在網頁上可以直接通過一個超鏈接調用。
超鏈接格式:
協議://參數
3、示例
new.reg文件
Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\Imou] "URL Protocol"="D:\\Software\\imou\\bin\\imou.exe" @="ImouProtocol" [HKEY_CLASSES_ROOT\Imou\DefaultIcon] @="D:\\Software\\imou\\bin\\imou.exe,1" [HKEY_CLASSES_ROOT\Imou\shell] [HKEY_CLASSES_ROOT\Imou\shell\open] [HKEY_CLASSES_ROOT\Imou\shell\open\command] @="\"D:\\Software\\imou\\bin\\imou.exe\" \"%1\""
index.html文件
<html> <body> <a href="imou://">運行</a> </body> </html>
點擊運行就會出現