Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

image randomiser code, easier way?

Hi I got this code that will post a random image every time the page refreshes

my problem is I've got Hundreds of images, so is there a way to make this easier then writing the code for every image

can i let it get the images from a folder or my flicker account randomly without posting the links for every single one

Here is the code, thank you for your help:

<SCRIPT LANGUAGE="Javascript">

function banner() { } ; b = new banner() ; n = 0

b[n++]= "<A HREF='URL LINK' ><IMG name=randimg SRC='https://image/ Link.jpg' border='0' ></A>"

b[n++]= "<A HREF='URL LINK' ><IMG name=randimg SRC='https://image/ Link.jpg' border='0' ></A>"

b[n++]= "<A HREF='URL LINK' ><IMG name=randimg SRC='https://image/ Link.jpg' border='0' ></A>"

b[n++]= "<A HREF='URL LINK' ><IMG name=randimg SRC='https://image/ Link.jpg' border='0' ></A>"

b[n++]= "<A HREF='URL LINK' ><IMG name=randimg SRC='https://image/ Link.jpg' border='0' ></A>"

i=Math.floor(Math.random() * n) ;

document.write( b[i] )

</SCRIPT>

</div>

1 Answer

Relevance
  • 6 years ago

    If you rename your files, say image1.jpg, image2jpg, image3.jpg, then you could just build the filename using the random number which is generated. e.g.

    <SCRIPT LANGUAGE="Javascript">

    function banner() {

    i=Math.floor(Math.random() * 10);

    var src="<a href='link'><img src='image' + i + '.jpg'>";

    document.write(src);

    }

Still have questions? Get your answers by asking now.