1. 程式人生 > >用JavaScript呼叫.exe檔案 相容瀏覽器

用JavaScript呼叫.exe檔案 相容瀏覽器

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 。因為這裡用的是寫字板測試的,你可以在登錄檔中,改成其他任何你要的程式。