Keywords: browser,application,url protocol,windows,mac,ie,chrome,safari.
Os:windows 7, OS X Yosemite.
Windows:
1. Write a C + + application with the following code:
#include <iostream>#include<string>using namespacestd;intMainintargcChar*argv[]) { if(Argc >1) {std::stringArgi (argv[1]); cout<<argi<<Endl; } cout<<"Press any key to continue"<<Endl; inti; CIN>>i; return 0;}
2. Create a new file Myapp.reg on Windows with the following file contents:
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\ ""
Note: Update "l:\\dev\\myapp\\debug\\myapp.exe\" to the path where MyApp.exe is located.
Run Myapp.reg on Windows to add content to the registry, such as:
4. Write an HTML test code as follows, save to file myapptest.html:
<!DOCTYPE HTML><HTML><Body>file URL or path:<inputID= ' Fileinput 'type= ' text '/><BR><Buttontype= ' button 'onclick= ' window.location.href = ' myapp://command=open&file= '+ encodeuricomponent (document.getElementById ("Fileinput"). Value) '>Open in MYAPP</Button><Buttontype= ' button 'onclick= ' window.location.href = ' myapp://command=insert&file= '+ encodeuricomponent (document.getElementById ("Fileinput"). Value) '>Insert in MYAPP</Button></Body></HTML>
To run myapptest.html on Windows with a browser, click "Open in MyApp" and the results are as follows:
Os x:
Open your project with Xode
1. Select your project.
2. Select your target.
3. Open Info tab.
4. add a new URL below the URL types.
Such as:
Running url:myapp://in Safari will launch the app.
Launching the application from the browser-application URL