前幾天,做項目時候用到js調用本地的程序,找了好多資料,一種是寫入注冊表,一種是寫一個瀏覽器插件,相對來說,寫一個注冊表更簡單一點,因為需求很緊。下面就是我的總結,希望可以對你們有所幫助,具體從哪里找的忘了,如果也有看見的煩勞煩告知一下,不勝感激。

第一步:
寫入注冊表,注冊表示例
Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\openNotepad] @="URL:openNotepad Protocol" "URL Protocol"="" [HKEY_CLASSES_ROOT\openNotepad\DefaultIcon] @="TestKZT.exe,1" [HKEY_CLASSES_ROOT\openNotepad\shell] [HKEY_CLASSES_ROOT\openNotepad\shell\open] [HKEY_CLASSES_ROOT\openNotepad\shell\open\command] @="cmd /c set m=%1 & call set m=%%m:openNotepad:=%% & call \"C:\\Windows\\TestKZT.exe\" %%m%% & exit"
保存為1.reg,運行就好
第二步,用瀏覽器調用並傳入參數,示例
<!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="openNotepad:www.baidu.com">百度</a> </div> </body> </html>
即可調用外部程序
其他注釋:
示例調用的是C:\\Windows\\TestKZT.exe的自定義程序,其他類似,傳入參數方式相似
這個就不需要什么小例子了,如有需要,留下郵箱。
