我在注册表中创建了一个名为fdmyalbs
的自定义协议.禁用此协议将执行PowerShell脚本,该脚本暂时将接收到的字符串(命令+参数)记录到预定义的文件中.
当使用Windows的文件资源管理器并在地址字段中输入字符串fdmyalbs:MyApp?data=sdfsdfsdfsfdsf sdfsdfsdfsdfsdfsdf
时,创建的文件显示fdmyalbs:MyApp?data=sdfsdfsdfsfdsf%20sdfsdfsdfsdfsdfsdf
,除了空白被%20
替换外,这正是输入的内容.
这意味着自定义协议定义是正确的,并按预期激活脚本. 现在,我正在try 使用以下代码在vanilla个JavaScript函数中执行相同的操作:
:
:
var l_Test_URL = 'fdmyalbs:MyApp?data=sdfsdfsdfsfdsf sdfsdfsdfsdfsdfsdf' ;
const fetchPromise = fetch(l_Test_URL);
fetchPromise
.then((response) => {
if (!response.ok) {
throw new Error(`HTTP error: ${response.status}`);
}
return response.json();
})
.then((data) => {
console.log(data[0].name);
});
:
:
此代码触发一条错误消息,其内容为:Fetch API cannot load fdmyalbs:MyApp?data=sdfsdfsdfsfdsf%20sdfsdfsdfsdfsdfsdf. URL scheme "fdmyalbs" is not supported
.
我的理解是,fetch
在这种情况下是不合适的.我正在寻找一种替代方法(而不是FETCH)来完成这项工作.
任何建议都将不胜感激.