自定義協議從瀏覽器中啟動本地應用程式
阿新 • • 發佈:2019-01-28
1. 需要啟動的本地應用程式為:
e:\SRC\Test\MyApp\bin\Debug\MyApp.exe
2. 編輯登錄檔匯入檔案: MyApp_Disk_D.reg
內容如下:
3. 將上面的檔案匯入到登錄檔.Windows Registry Editor Version 5.00 [HKEY_CLASSES_ROOT\myapp] @="URL:AutoHotKey myapp Protocol" "URL Protocol"="" [HKEY_CLASSES_ROOT\myapp\DefaultIcon] @="myapp.exe,1" [HKEY_CLASSES_ROOT\myapp\shell] [HKEY_CLASSES_ROOT\myapp\shell\open] [HKEY_CLASSES_ROOT\myapp\shell\open\command] @="\"e:\\SRC\\Test\\myapp\\bin\\Debug\\myapp.exe\" \"%1\""
4. 在IE中輸入如下內容,即可啟動應用程式myapp.exe
myapp://parameter
5. 至此在大多數瀏覽器中,已經能夠通過自定義的協議啟動指定應用程式了.
6. 對於Chrome瀏覽器,若不能啟動指定的應用,請檢視如下幾點
6.1 自定義協議後的引數不能太短,最好超過三個字元,並且最好不要用一些常用的關鍵字.
6.2 配置Chrome的阻止的協議列表, 配置檔案路徑如下,不用的安裝路徑,還不用的使用者,路徑稍有不同:
C:\Users\liu\AppData\Local\Google\Chrome\User Data\Local State
開啟此檔案後,找到如下內容:
"protocol_handler": { "excluded_schemes": { "afp":true, "data":true, "disk":true, "disks":true, "file":true, "hcp":true, "iview":false, "javascript":true, "mailto":false, "ms-help":true, "ms-windows-store":false, "myapp":false, "news":false, "nntp":true, "shell":true, "snews":false, "tencent":false, "vbscript":true, "view-source":true,
確保我們自己定義的協議 myapp 後面的值為"false", 即不在被排除的列表中.
7. 通過網頁中的連線開啟本地相關應用程式的示例如下
<!DOCTYPE html>
<html>
<head>
<title>Web Automation</title>
<script type="text/javascript">
function dicom() {
var ret = confirm('Start Dicom Search?');
var aetitle = document.getElementById("txtAETitle").value;
var patientid = document.getElementById("txtPatientId").value;
var accessnumber = document.getElementById("txtAccessionNumber").value;
var local = document.getElementById("cbLocal").checked;
if (ret == true) {
window.location = 'myapp://,query,' + aetitle + ',' + patientid + ',' + accessnumber + ',' + local;
}
return;
};
function study() {
var ret = confirm('Open Study?');
var aetitle = document.getElementById("txtAETitle").value;
var studyInstanceUId = document.getElementById("txtStudyInstanceUId").value;
if (ret == true) {
window.location = 'myapp://,study,' + aetitle + ',' + studyInstanceUId;
}
return;
};
function LaunchApp() {
try {
var ret = confirm('Start myapp?');
if (ret == true) {
window.location = 'myapp://,start';
}
}
catch (ex) {
errMsg = "啟動 myapp 報錯.\n\n";
alert(errMsg);
}
return;
};
</script>
<style type="text/css">
#txtAccessionNumber
{
width: 191px;
}
#txtStudyInstanceUId
{
width: 901px;
}
</style>
</head>
<body>
<div>
<input type="button" value="Open IView" onclick = "LaunchApp()" /><br /><br />
<label>AE Title: <input id="txtAETitle" type="text" value="AETITLE" /></label>
<label>PatientID: <input id="txtPatientId" type="text" value="115042300003"/></label>
<label>AccessionNumber: <input id="txtAccessionNumber" type="text" /></label>
<label>Search Local:<input id="cbLocal" type="checkbox" value="local" /></label><br />
<label>StudyInstanceUId: <input id="txtStudyInstanceUId" type="text" value="1.2.392.200036.9125.2.138612190166.20150423000027"/></label><br /><br />
<input type="button" value="Dicom Search" onclick = "dicom()" /><br /><br />
<input type="button" value="Open study" onclick = "study()" />
</div>
</body>
</html>