views:

346

answers:

1

I have a form where user fills up (jsp page). One of the input is of type "file". There is a preview button which will pop up a new window and using javascript to layout the filled up form for display. The "file" input will be display as a hyperlink and when the user clicked on the hyperlink, it is supposed to open the attachment. So if you attached pdf, I would expect that when I clicked on the hyperlink, foxit reader will open. if it is a text file, notepad will open.

I tried using file:// but nothing seems to happened. it seems to be a security feature in MSIE where file:// protocol is locked down.

how do you go about implementing this feature without(ActiveX, ajax) ?

+3  A: 

file:// only points to the local file system on the user's computer, and is often subject to more locked down security measures. It simply can't be relied upon the the browser will even allow file:// protocol access.

The only way to safely do what you want is to fully submit the form with the file and use a server side language (PHP, ASP.NET, Rails, Django, take your pick) to render out a page with the 'pretty' layout of the form data as well as a preview of the document. This is how forums do it, you hit the "preview" button and your post is submitted to the server, the server renders it for your approval, you approve it, and it gets saved to the database and published. If you don't approve it, it gets discarded and never makes it to the database.

If you don't want the user to leave the page, you can roll this into your validation and do an AJAX postback. There are javascript libraries specifically for serializing and transmitting forms silently like this, and then returning the results. JQuery Forms is a good example of this (note: requires JQuery).

Soviut
I think he means before the user uploads there file. Like to check its the right file. So if they say enter that they want to upload "C:/MyTextdocument.txt" per se, He wants to go open "file://c:/MyTextdocument.txt" which I would expect to work? Because the user has specified the local path to the file.
Thqr