zeroin23
zeroin23

Reputation: 1821

opening a local file in a webpage using file://

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)?

Upvotes: 2

Views: 1231

Answers (1)

Soviut
Soviut

Reputation: 91625

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).

Upvotes: 3

Related Questions