DL Image endless loop?

Questions about programming languages and debugging
Post Reply
User avatar
ayu
Staff
Staff
Posts: 8109
Joined: 27 Aug 2005, 16:00
18
Contact:

DL Image endless loop?

Post by ayu »

This code is suposed to download a picture from a site in an endless loop, but i tested it on my own site then i checked my apache logs and it says the picture only was downloaded once.

<img width="100" height="100" src="http://site/image.jpg" onload="this.src=http://site/image.jpg?' + Math.random();" />

User avatar
FrankB
Ph. D. in Sucko'logics
Ph. D. in Sucko'logics
Posts: 315
Joined: 06 Mar 2006, 17:00
18
Location: Belgistahn
Contact:

Re: DL Image endless loop?

Post by FrankB »

neo130 wrote:This code is suposed to download a picture from a site in an endless loop]
No it doesn't, the script is :
1. completely wrong.
2. only executed once.
neo130 wrote: but i tested it on my own site then i checked my apache logs and it says the picture only was downloaded once.
Well, what did you expect ??? (you asked the browser to load the page and picture only once also. So..)
neo130 wrote: <img width="100" height="100" src="http://site/image.jpg" onload="this.src=http://site/image.jpg?' + Math.random();" />
Aw.. bad bad code.
If you want images to show up randomly, use REAL integers, not floating decimals and put them BEFORE the extention like here :

Code: Select all

 
(img src="/path/to/pic/pic.1jpg" 
onclick="this.src='/path/to/another/pic/'+Math.floor(Math.random()*10)'+'.jpg'" )
assuming you have at least ten images stocked in that same directory.

Post Reply