Skip to content Skip to sidebar Skip to footer

Unusual Issue With Html Image And 'file://' Specified Src

I'm loading an image on the page with a 'file:///some_dir/image.jpg' src path. I can access the image in a regular tab using this path. Also, saving the page as HTML and using this

Solution 1:

Websites are not allowed to use local files on the user's computer. Use a relative path to from the html file's directory.

You can also encode and embed the image directly:

How to embed the encoded stuff: http://www.sweeting.org/mark/blog/2005/07/12/base64-encoded-images-embedded-in-html Python Encoding Instructions: http://www.daniweb.com/software-development/python/code/216635

Solution 2:

The problem is you are trying to load a file directly off of a clients computer. Browsers prevent this.

You can read about the exact details here:

http://en.wikipedia.org/wiki/Same_origin_policy

It is called the Origin Policy. It prevents malicious sites from directly loading files off of a clients computer. Try using a relative path from your page to display the image.

In some situations (rare) I've used a light web server to host the site so that I could load the files from the server (as opposed to having it load off of what the browser sees, as a clients computer).

Post a Comment for "Unusual Issue With Html Image And 'file://' Specified Src"