views:

303

answers:

3

I am writing a Firefox extension and would like the users to be able to change an image on a web page with a local image. Is it possible, using JavaScript, to change the image source with an image that is saved on the user's local machine?

Let me know if you need more information. Thanks

A: 

JavaScript cannot access the local filesystem for security purposes. Your plug-in will have to work-around this problem.

Diodeus
A: 

I think this hacks post has some useful information on recent HTML5 feature work to support access to local files:

http://hacks.mozilla.org/2010/02/an-html5-offline-image-editor-and-uploader-application/

I'm not sure about using local files as images directly, but at worst, using the techniques demonstrated there, you could create a data: URL to use instead.

Jeff Walden
+1  A: 

You can set SRC of an image to a "file://" URI obviously, or any string for that matter. But getting the path may prove more tricky - you'll have to use browser's internals to grab the path.

Of course this is completely impossible from a webpage javascript, but an extension is in a much weaker sandbox than a page, and you can do quite a bit about the filesystem, so answers that suggest it's impossible are plain wrong.

SF.