I'm creating a web page with within the index.html a slideshow of 8 images. Now if I add these images, and I run it in a random browser it just works perfectly fine, while adding some javascripts to get a beautifull index page with a slideshow, it just does not do anything. I get a white page full of bugs etc. Can some one please tell me what I did do wrong?
<html> <head> <script src="http://code.jquery.com/jquery-latest.min.js"></script> <script type="text/javascript"> <!-- var img1 = new Image() img1.src ="F:\\Thema B\\website1\\img1.jpg" var img2 = new Image() img2.src ="F:\\Thema B\\website1\\img2.jpg" var img3 = new Image() img3.src ="F:\\Thema B\\website1\\img3.jpg" var img4 = new Image() img4.src ="F:\\Thema B\\website1\\img4.jpg" var img5 = new Image() img5.src ="F:\\Thema B\\website1\\img5.jpg" var img6 = new Image() img6.src ="F:\\Thema B\\website1\\img6.jpg" var img7 = new Image() img7.src ="F:\\Thema B\\website1\\img7.jpg" var img8 = new Image() img8.src ="F:\\Thema B\\website1\\img8.jpg" //--> </script> </head> <body> <img src="F:\\Thema B\\website1\\img.jpg" name="slide"> <script type="text/javascript"> <!-- var pic=1 function slides() { if (!document.images) return document.images.slide.src=eval("img"+pic+".src") if <pic < 8) pic++ else pic = 1 setTimeout("slides()",500) } slides() //--> </script> </body> </html>
So... at first glance, it looks like this line is the issue
document.images.slide.src=eval("img"+pic+".src")
If you look, you are creating filenames of 'img1.src'. However, you actually want 'img1.jpg'.
Try this to fix the problem...
document.images.slide.src=eval("img"+pic+".jpg")
Also, you may likely need to put the full path there as well... so you may want to use something like
document.images.slide.src=eval("F:\Thema B\website1\img"+pic+".jpg")
I see two problems:
1) there is a typo in if line. You typed
if <pic < 8)
and i think you wanted
if (pic < 8)
2) reading images from disk. Javascript blocks that due to security reasons
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.