从浏览器启动应用程序 - Application URL
关键字:Browser,Application,URL Protocol,Windows,Mac,IE,Chrome,Safari。
OS: Windows 7, OS X Yosemite。
Windows:
1.写一个C++ 应用程序,代码如下:
#include <iostream> #include <string> using namespace std; int main(int argc, char* argv[]) { if(argc > 1) { std::string argi(argv[1]); cout<<argi<<endl; } cout<<"Press any key to continue"<<endl; int i; cin>>i; return 0; }
2.在windows上新建文件MyApp.reg,文件内容如下:
Windows Registry Editor Version 5.00
[HKEY_CLASSES_ROOT\MyApp]
@="Open MyApp"
"URL Protocol"=""
[HKEY_CLASSES_ROOT\MyApp\shell]
[HKEY_CLASSES_ROOT\MyApp\shell\open]
[HKEY_CLASSES_ROOT\MyApp\shell\open\command]
@="\"L:\\Dev\\MyApp\\Debug\\MyApp.exe\" \"%1\""
注:把"L:\\Dev\\MyApp\\Debug\\MyApp.exe\"更新为MyApp.exe所在的路径。
在Windows上运行MyApp.reg添加内容到注册表,如下图:
4.写一段HTML测试代码如下,保存到文件MyAppTest.html:
<!DOCTYPE html> <html> <body> file URL or path: <input id='fileinput' type='text'/><br> <button type='button' onclick='window.location.href = "MyApp://command=open&file=" + encodeURIComponent(document.getElementById("fileinput").value)'>Open in MyApp</button> <button type='button' onclick='window.location.href = "MyApp://command=insert&file=" + encodeURIComponent(document.getElementById("fileinput").value)'>Insert in MyApp</button> </body> </html>
分别在Windows上用浏览器运行MyAppTest.html,点击“Open in MyApp”,结果如下:
OSX:
用Xode打开你的project
1.选择你的 project.
2.选择你的 target.
3.打开 Info tab.
4.在URL Types下面添加新的URL.
如下图:
在Safari里面运行URL:myapp://,将启动这个应用。
/************************************
ldlchina
QQ:3110615
************************************/
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 如何编写易于单元测试的代码
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 周边上新:园子的第一款马克杯温暖上架
· Open-Sora 2.0 重磅开源!
· 分享 3 个 .NET 开源的文件压缩处理库,助力快速实现文件压缩解压功能!
· Ollama——大语言模型本地部署的极速利器
· DeepSeek如何颠覆传统软件测试?测试工程师会被淘汰吗?