-1

I want to let the user click on a file (let's say a .doc link) in the browser and it will open the native desktop application (microsoft word in this case).

And when the user saves the document it will be saved in the web.

Is there a way doing this with Javascript/HTML 5 or does the user have to download the file to be able to open it with the native application?

never_had_a_name
  • 90,630
  • 105
  • 267
  • 383

2 Answers2

2

If you provide a link to this file on your page:

<a href="http://example.com/foo.doc">Open foo.doc</a>

it will be opened with the default application associated with this extension on the user computer.

If you want it to open inline inside the browser without any popup dialogs you could try setting the Content-Disposition HTTP header on the server: Content-Disposition: inline;filename=foo.txt. Of course the client application must have a plugin version which works with the browser and is capable of opening files inline (this is the case for example with Adobe Acrobat Reader).

As far as the second part of your question is concerned, there's absolutely nothing in the HTTP protocol specification allowing you to do this, so in order to achieve it it needs to be something custom-made. The client program needs to be able to talk to the server and send the modified version of the file back.

Community
  • 1
  • 1
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
  • It is so sad that this is not easily possible... A simple "save handler URL" system that the local app (or the OS) uploads changed files back to could have fundamntally changed the way CMSs work (people being able to use their favourite apps to edit online content) – Pekka Oct 17 '10 at 19:16
  • @Pekka, no, that's a huge security issue. Please let's leave client applications run in a sandbox and never allow them sending anything back. – Darin Dimitrov Oct 17 '10 at 19:17
  • @Darin this *could* be implemented securely, say through a one-time upload token, or additional authentication... Not much different from any other web request really – Pekka Oct 17 '10 at 19:17
  • @Pekka, it's different than an ordinary web request because an ordinary web request cannot read files on your client computer while a browser plugin can. – Darin Dimitrov Oct 17 '10 at 19:23
  • @Darin no, what I mean is have a convention to 1. Download the file and store it locally 2. Open it locally e.g. using Word or OpenOffice or whatever 3. After exiting the local app, have the changed file be uploaded back to an upload handler (as a normal HTTP file upload) instead of it vanishing in the temp files folder (as is the case now). – Pekka Oct 17 '10 at 19:27
  • @Pekka. So with Darin's solution above, even if the file is opened with the native application it's pointless because the file is in the local temp folder after he has saved it right? Doesn't HTML5 fix this somehow? – never_had_a_name Oct 18 '10 at 02:08
  • No; HTML5 does not change this. – SLaks Oct 18 '10 at 02:28
  • @ajsie what @SLaks says. And nope, AFAIK there is nothing in HTML 5 to remedy this, either - it has local storage functions but they are for storing data from the web site in a local cache – Pekka Oct 18 '10 at 09:33
1

It is not possible to save back to your site unless the client application specifically supports it.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964