There is a method with HTML5, but it requires the user to dump the file into the target folder or use the field <input type="file"/>, otherwise it will be a security problem.
Using the API File, you can read files, and especially you can use the method FileReader.readAsDataURLto set the content as the URL data:for the image tag.
Here is an example:
$('#f').on('change', function(ev) {
var f = ev.target.files[0];
var fr = new FileReader();
fr.onload = function(ev2) {
console.dir(ev2);
$('#i').attr('src', ev2.target.result);
};
fr.readAsDataURL(f);
});
http://jsfiddle.net/alnitak/Qszjg/
source
share