I was learning about custom protocols for few days, and there's one thing that I don't understand.
I know how to start an app with custom protocol, but My question is,
Is it possible to get apps response and print it in Web Browser using javascript?
For example If I will send request to protocol myapp:// , that will open an app written in C#, and that app will return string "This is response" can to print it in Web Browser?
If so, can you help me to accomplish it?
Thanks in advance.
1 Answer
Internet protocols aren't all about browsers.
mailto: causes an action in an email program (e.g. start a new email)
ftp: causes an action in an FTP program (which might be integrated into a web browser or Windows Explorer)
gopher: (well, that's not really prevalent anymore)
myapp:// will cause your (C#) app to start running. At that point, it can do anything a C# app can do. One thing it could choose to do is create a .html file on disk, and use
Process.Start("file://Path/To/My.html")
to cause the default web browser to open the document it just created.
UPDATE
You can certainly have your myapp:// protocol handler send an update to the web server that hosts the page in question. My assumption here is that the myapp:// handler is running on a client machine, and there is a web server on a different URL http://mydomain.com serving a page that includes a myapp:// reference.
- Web server renders a page that includes both a myapp:// URL and Ajax code to periodically query the web server for updates to part of the HTML body.
- User clicks the myapp:// URL
- Protocol handler runs
- Protocol handler sends an update to the web server, e.g.
http://mydomain.com?user=joe&result=123
- Web server uses
?user=joe&result=123
to update response next time the Ajax callback is initiated - Ajax callback gets updated data for page from web server, updates page.
-
And is it possible to print result to the same window from where was the request sent. To force for example: myapp:index to have the result in its body. Commented Nov 13, 2012 at 21:18
-
It depends on the protocol. If it's built into the browser, and the mechanism used to run the handler provides a way to pass data back, then it can. If it just starts the application in the OS's standard way, there's no communication path back to the browser.– BarmarCommented Nov 13, 2012 at 21:24
-
1@RenéBeneš: If your protocol handler is a browser plugin, then it can be done. If it is not a browser plugin, the only path to open a document in a browser that I'm aware of is the one I outlined in my answer. Of course if your protocol handler also implements the http protocol (i.e. if you include a mini web server) it could do something like
Process.Start("http://localhost/someData:9999")
where 9999 is some port that your mini web server listens to for http requests (in addition to "listening" for myapp:// requests).– Eric J.Commented Nov 13, 2012 at 22:24 -
@RenéBeneš: Alternatively, your protocol handler could call back to your web server and tell the web server what to add to the document body. Your HTML page could use Ajax to load that new content. I'll update my answer with that.– Eric J.Commented Nov 13, 2012 at 22:28
-