如何注冊自定義 URL 協議,以便當我將協議作為后綴傳遞時,該 URL 將在該瀏覽器中打開。我創建了一個 chrome > shell > open > 命令,而不是默認的 chrome.exe 完整路徑。但是,當我將該協議添加到 url 例如 chrome: http://google.com時,它不會在 chrome 中打開 google.com,它只會打開空白的 chrome 頁面。
先感謝您
uj5u.com熱心網友回復:
協議處理程式只是使用完整的 url 作為引數呼叫已注冊的命令。
如果在注冊表中設定"c:\path\to\chrome.exe" %1為命令然后啟動chrome:http://google.com,Chrome.exe 將chrome:http://google.com作為引數啟動,這將不起作用,因為 Chrome 不知道如何處理該 url。因為你說它只是打開一個新的空白頁面,我懷疑你甚至沒有%1在注冊表中指定。
如果您想為第 3 方應用程式發明一個新協議,您必須制作自己的啟動器,在將 url 傳遞給 Chrome 之前轉換它。
批處理啟動器示例:
@echo off
setlocal ENABLEEXTENSIONS DISABLEDELAYEDEXPANSION
if /I "%1"=="Install" goto install
set url=
echo I was started with %*
for /f "tokens=1,* delims=:" %%a in ("%*") do set url=%%b
echo URL to use is %url%
if defined url start chrome.exe %url%
goto :EOF
:install
reg add HKCU\Software\Classes\Chrome /v "URL Protocol" /d "" /f
reg add HKCU\Software\Classes\Chrome\shell\open\command /ve /f /d """"%~f0""" %%1"
echo Registered, now testing...
start chrome:http://google.com
(另存為.bat,在cmd.exe中以Install為引數執行一次)
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/522910.html
