Link to home
Start Free TrialLog in
Avatar of jerryleeclark
jerryleeclarkFlag for United States of America

asked on

Clipboard, launch local application or exe from javascript using Plug-in

Hello all and thanks ahead,
I am looking for an answer or advice on how to do two seemingly common things that may be needed in the world of web apps consumed on a corporate lan. I want my javascript enabled web page to be able to set the client/local clipboard with text and also to be able to launch a client/local application .exe. Now. I have done some reading and it seems IE has some easier provisions to do these two things, but Mozilla FF has some hurdles. I looked into perhaps making a plug -in for FF to ease the pain, but that seems to be a pain as well. I am willing to to take the pain of creating a plug in but need some help (an overview would be nice) or some explicit code to create the plug-in and then some explicit javascript to exploit the plug-in. Since it is a corporate lan, distribution and trust of the plug-in should not be an issue. It would be nice if the plug-in allowed the set clipboard AND enabled the launching of the local app.
It is also hoped that I could create plug-ins for each browser type so as to 'normalize' the javascript. That is, to not worry about browser type in javascript with the expectation that the client will have the plug-in. The setting of the clipboard and launching of the local app is something the user will be doing a lot of, so hopefully the browser will not complain with security prompts every time a user activates one of these controls.
Any Help?
Thanks....
ASKER CERTIFIED SOLUTION
Avatar of wdosanjos
wdosanjos
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jerryleeclark

ASKER

OK. So I have spent several hours chasing down this custom protocol thing. Seems simple enough, but I must have some syntax incorrect or something. Using FF 3.0. On webserver/in web page:
 
<html>
 <head><title>blah</title></head>
 <body><a href="blah:">click for blah</a></body>
</html>

Open in new window


and in about:config in FF (well easier to show the pref.js):

 
user_pref("network.protocol-handler.app.blah", "C:\\WINDOWS\\system32\\notepad.exe");
user_pref("network.protocol-handler.external.blah", false);

Open in new window


I get the dreaded : Firefox doesn't know how to open this address, because the protocol (blah) isn't associated with any program.

Any help?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Notepad launches now albeit with an error (The filename, directory name, or volume label syntax is incorrect.). This maybe due to an incorrect quotation mark around the %1. Perhaps to open a blank notepad this way still requires an argument (blank argument)? To any extent, can you show me how to send arguments? Sorry about the hand holding:\
You can try the following url on the browser:
blah:mytext.txt
This will have the same effect as the following command line:
notepad.exe mytext.txt
If you change the following value:
[HKEY_CLASSES_ROOT\blah\shell\open\command]
@="\"C:\\windows\\notepad.exe\" \"%1\""
To:
[HKEY_CLASSES_ROOT\blah\shell\open\command]
@="\"C:\\windows\\notepad.exe\"
Then no parameters will be passed to Notepad.

I think the end goal should be to create a custom protocol that links to your program, which should know based on the parameter passed what enterprise application to invoke.
notepad says 'Can not find the blah:text.txt file. Do you want to create a new file?' (I am making sure that the file and notepad are in the same directory. Tried in the default location first and then tried right on c:\ by copying notepad to c:\)

Also, would <a href="blah:">
be equivalent to notepad.exe  from the command line? ie no arguments?

I checked the registry entries after running my blah.reg file. And I checked the entries against those for mailto. There were some subtle differences in quotation and I have tried to set blah up similar to mailto but blah still gives the can't find file error.
Notepad is not meant to be a custom protocol, so most practical scenarios won't work.  Notepad is only being used to illustrate that the registry configuration causes the protocol to invoke the given executable.

The article below provides a step-by-step guide on creating a custom protocol.  Please take a look and implement the Alert example.  You should be able to build on top of it for your particular scenario.
http://msdn.microsoft.com/en-us/library/aa767914%28VS.85%29.aspx

Yes, blah: is equivalent to notepad.exe from the command line with no arguments.

I'm not sure where notepad is creating the files.  Just try blah:myfile.txt, create a new file, then save it.  The next time you enter blah:myfile.txt you should get the file you saved.

I hope this helps.
So, the %1 will contain the entire URL? (blah:myfile.txt) No way around that? No regex magic I can do in the open registry key?
The %1 contains the "myfile.txt" string. Whatever comes after blah: is passed as a parameter.
From your link: 'If the specified open command specified in the registry contains a %1 parameter, Internet Explorer passes the URL to the registered protocol handler application. '

From StackOverflow: 'The MSDN link is nice, but the security information there isn't complete. The handler registration should contain "%1", not %1. This is a security measure, because some URL sources incorrectly decode %20 before invoking your custom protocol handler.

PS. You'll get the entire URL, not just the URL parameters. ....'

If this is the case, indeed notepad will have troubles as it is having for me. Saving the notepad file goes to my desktop and the file is named 'blah'. Attempting a   file>save as   to see the path fails, likely b/c of having a ':' in the file name. It looks like using this method to launch applications will mandate also creating an extra .exe that is the 'protocol handler'. So in this case I have to create an .exe to launch another .exe?
You are right %1 contains the full URL.

You are on the right track. You need to create an exe (protocol handler) that will interpret the URL and launch your other exe's.
Can you provide a good link that discusses creating a 'companion' protocol handler application that stays resident (ie doesn't start a new instance every time the browser invokes the protocol) and handles multiple protocols?
Thanks wdosanjos. You answered when no one else did!