TuftyTrue wrote:
Hi,
On my site the user can browse to an image with <input type=file etc>.
Althrough I have no problem swapping images with:
document.getElementById('PictureToDisplay').src =
URLtoPictureOnWebServer.src;
I cant get it to work with:
document.getElementById('backgroundLayer').src =
PathToPictureOnLocalDrive.src
I've tried hardcodeing the variable (with and without quotes) with all
the obvious values:
"C:\pics\mypic.jpg", "file:///c:/pics/mypic.jpg" etc etc but cant get
it to work.
Any ideas why its fine with remote pictures, but not with local ones?
(Also, just to muddy the waters even more, I've managed to display a
local image using a style.setbackgroundimage="path to local image", but
abandoned this as I cound not get the image to re-size :( )
Any help gratefully recieved
Regards
Eadmund
Hi,
AFAIK: What you want cannot be done with JavaScript.
Local filesystem is not accesible via a random webpage's JavaScript (which
is by design and good).
The only exception to that rule is a file-upload, but that is crippled too
so JavaScript cannot 'see' the values (files) used. (again by design).
Some/many browsers let you retrieve html-files from the local filesystem
(not via http), and then this restriction is lifted.
I think this is called 'same origin policy' or something like that.
So if the html-file originates from your local hd, the images can be found,
if the html-file originates from some website (via http) your local
filesystem is not accesible (not via a hardcoded link, and not via JS).
This is good. Think about what would happen if any webpage could browse your
filesystem behind your back...
I think the only way out is:
1) upload the file to the server
2) offer the page with the (freshly uploaded) backgroundimage coming from
the server (http).
Maybe you can lift this restriction via 'trusted zones' in IE. Don't know.
Just my 2 cent.
Regards,
Erwin Moller