Launching the application from the browser-application URL

Source: Internet
Author: User
Tags file url

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.