20

In my web page, I have to start a desktop application on the client's computer if it's installed. Any idea how I can do this?

If the application is MS Office or Adobe Reader, I know how to start them, but the application I want to start is a custom application. You can not find it on the internet.

How can I open the application?

gen_Eric
  • 223,194
  • 41
  • 299
  • 337
hguser
  • 35,079
  • 54
  • 159
  • 293
  • Why don't you just ask the user to open the program themselves? – gen_Eric Jun 07 '11 at 13:18
  • 7
    Why do you layout your web page,why don't just ask the user to see the source code??? This is just the requirement. – hguser Jun 07 '11 at 13:24
  • "If the application is MS Office or Adobe Reader, I know how to start them", can you share how to start them up? – Meir Nov 11 '22 at 18:13

6 Answers6

20

Basically it's not possible to achieve unless an application registers a protocol that will trigger it. If it does that all you need to do is to provide a link using this protocol

yourcustomapp://some.parameters

Another way the 3rd party app can integrate with the browser is if it hooks to it as a plugin. This is how flash apps work etc.

If the app you are trying to launch does not support something like that it's going to be close to impossible to achieve what you want.

RaYell
  • 69,610
  • 20
  • 126
  • 152
  • 7
    can you provide a link explaining how to define and register such a protocol? – retrodrone Jun 07 '11 at 13:26
  • The application would have to already be running, or at least some agent would have to be running, on the client computer. It would have to be listening on some port. – Pointy Jun 07 '11 at 13:41
  • This is the method I've settled on for now, but I'm missing one piece: how do I trigger the application to "just run" on page load? It SEEMS as though a protocol handler is API-restricted to needing user interaction (an actual click by a user), but all I want is for the application to launch on page load. I don't mind if there are security warnings, etc. (as expected with any protocol handler link)... I just want it to fire up. Any ideas? – Greg Pettit Apr 16 '14 at 15:39
  • for registering such a protocol you can look at [this answer](http://stackoverflow.com/a/37601807/1018842). I tested this in Chrome version 58.0.3029.81. The only thing not working in chrome is typing the protocol in the adres bar which does seem to work in other browsers. – ColmanJ Apr 24 '17 at 08:25
  • This is epic!! Create a small server listening on a port and trigger it remotely with get requests and have that served app do stuff. Why did I not think about this! – dewwwald Apr 23 '19 at 22:08
10

The browser sandbox prohibits you from executing local resources, for good reason - to thwart a website destroying your box with malicious code. I've been researching the same functionality.

The only solution I've found is to build an extension in Mozilla Firefox which can launch your app. Extensions live outside the sandbox so they can execute local resources. See this page for how to do that. You may be able to do it cross-browser using crossrider, though I haven't had success with that yet.

You could alternatively build a thick client populated from a web service, and launched from the browser through an extension as mentioned above. This is what I'm doing to get around the sandbox. I'm using local XUL for this.

See my question for additional discussion.

Community
  • 1
  • 1
retrodrone
  • 5,850
  • 9
  • 39
  • 65
8

First off - you can't do it using javascript in any sort of a portable mechanism.

If the application is ms office or adobe reader,I know how to startup them

No you don't - you know how to send a document, which the browser associates with these applications and invokes them supplying the name of the local copy of the response. You can't just start the programs.

You just need to do the same for your app - invent a new mime type (the major type would be 'application' and by convention, non-standard minor types are prefixed with 'x-', so you might use application/x-hguser) then associate that mimetype with the relevant program browser side.

i.e: You need to explicitly configure each browser

Fred
  • 2,402
  • 4
  • 31
  • 58
symcbean
  • 47,736
  • 6
  • 59
  • 94
  • 2
    can you provide a link with details about associating a custom mime type? This might be infinitely useful for a problem I'm trying to solve in a closed environment. – retrodrone Jun 07 '11 at 13:26
5

I already encouter that problem in some complex production environnements.

I do the trick using the following code :

function launch(p_app_path)
{
   var oShell = new ActiveXObject("WScript.Shell");
   oShell.Run('"' + p_app_path + '"', 1);
}

In IE options > Security > Customize the level > ActiveX controls and plugins > Initialization and script ActiveX controls not marked as safe for scripting, set the value to Ask or Active.

It isn't a security problem when your website is enclosed into a specific security context. And as they say, it's not worth it to build a gas plant.

Ivandolchevic
  • 184
  • 1
  • 3
1

JavaScript alone can't do this. (No, not even with MS Office or Adobe Reader.) Thankfully.

There are a number of old ways, including using ActiveX, which may work for your needs. As others have pointed out while typing this, you can customize responses based on the mime type or the protocol, etc.

Any way you look at it, you're going to need control over the end users' browser. If you're in a close environment where you can dictate policy (users must use a specific browser, with a specific configuration), then you're going to need to do that. For an open environment with no control over the end users, you're out of luck.

David
  • 208,112
  • 36
  • 198
  • 279
1

I'm actually having a lot of success right now with SiteFusion. It's a PHP client/server application framework that serves out XUL/JavaScript applications from a server deamon running in Apache. You access applications from a very thin client in XULRunner, or potentially off a web page using extensions. Clients can execute on any platform, and they're outside of the browser sandbox so you can access local resources such as executables. It'a a fairly elegant solution, their website provides great examples and documentation, and their forum is very responsive. I actually found a minor bug in passing arguments to local executables, posted a question about the forum, and it was fixed by the chief developer in under 15 minutes. Very impressive, overall!

retrodrone
  • 5,850
  • 9
  • 39
  • 65