0

This is working in my browser:

<!DOCTYPE html>
<html>
<body>

<img src="http://nineplanets.org/planets.jpg" 
onmouseover="this.src='http://nineplanets.org/planetorder.JPG';"
onmouseout="this.src='http://nineplanets.org/planets.jpg';">
</img>

</body>
</html>

But this is not working:

<!DOCTYPE html>
<html>
<body>

<img src="C:\Users\user\Desktop\WE\Pics\milk.png"
onmouseover="this.src='C:\Users\user\Desktop\WE\Pics\butter.png';" 
onmouseout="this.src='C:\Users\user\Desktop\WE\Pics\milk.png';">
</img>

</body>
</html>

Please answer as soon as possible and path to my images is totally correct!!

Guneet Kaur
  • 544
  • 1
  • 8
  • 26

2 Answers2

2

If you want to use paths pointing to your local hard drive, you will need to use the file protocol like this:

file:///c:/Users/user/Desktop/WE/Pics/milk.png

However, it's best practice to use relative URLs instead, for instance:

Pics/milk.png

will find the file milk.png in the Pics folder, where the Pics folder is alongside your HTML file.

Maximillian Laumeister
  • 19,884
  • 8
  • 59
  • 78
  • hey! could you please justify as why do we need this file protocol type as you mentioned above in your answer? – Guneet Kaur Oct 02 '15 at 19:50
  • @GuneetKaur As far as I know it's just one of the quirks (features?) of HTML. The file URL makes it so that there is a standardized URL format whether you're on Windows, Mac OS, Linux, etc.. You can read more [here](http://stackoverflow.com/a/12711835/2234742) and [here](https://www.cs.tut.fi/~jkorpela/fileurl.html). – Maximillian Laumeister Oct 02 '15 at 20:01
1

You cannot use paths pointing to a local hard drive. That would be a major security issue. you will have to either mount a localhost server or try using the file:// protocol.

taxicala
  • 21,408
  • 7
  • 37
  • 66