-1

I tried loading an web image, it works. But I want to load a client-side image.

$("#lol").live("click", function() {
 $(".main").html('<img src="file:///D:/lol.jpg" />');
})
  • 3
    I don't think javascript has this kind of functionality for security reasons. – Joseph Marikle Aug 10 '11 at 19:28
  • 1
    You CAN'T do that :) there's a reason why browser code can't access files on your system... – PhD Aug 10 '11 at 19:29
  • IE CAN do that after asking user to give the access – Mohsen Aug 10 '11 at 19:31
  • You can find your answer here: [http://stackoverflow.com/questions/13556812/using-this-with-filereader-to-target-result][1] [1]: http://stackoverflow.com/questions/13556812/using-this-with-filereader-to-target-result – Hamid Ghorashi Nov 22 '13 at 12:40

3 Answers3

1

Your src attribute needs to be accessible through the web through http(s). Remember, clients don't have access to your files, only what a web server can serve up to them.

FishBasketGordo
  • 22,904
  • 4
  • 58
  • 91
1

That's a browser security issue. If you were allowed to load local files at will you could exploit that in order to access remote files on the user machine.

Why do you need to do that? Maybe there is another way to accomplish what you want.

Ariel Popovsky
  • 4,787
  • 2
  • 28
  • 30
0

Specify the hosted url from where you are running the application. Something like http://localhost

Note: This will only work locally but not over the inernet. You should always use the application relative path for images.

$("#lol").live("click", function() {
    $(".main").html('<img src="http://localhost/applicationName/images/lol.jpg" />');
});
ShankarSangoli
  • 69,612
  • 13
  • 93
  • 124