If you can have <script src="some.js" type="text/javascript"></script> on the page, it can be anywhere on the page. More easily somewhere after where the image will be but, using onload, it could be anywhere on the page.
Using the above example (there are better ways to code that but, since it works, I will not go into that here), this could be in the some.js file:
Code:
//The array which is going to hold the image information. Store the image info along with their correct path; I've omitted the path here as I've stored the images in the same folder where my web page resides.
var imageArray = new Array();
imageArray[0] = "1.jpg"; //You can replace these image file names with your own image names.
imageArray[1] = "2.jpg";
imageArray[2] = "3.jpg";
imageArray[3] = "4.jpg";
function doIt()
{
var rand = Math.floor(Math.random()*4); //Generating a random number between 0 and 3 here in your case you can replace 4 with 11 if you have 10 images
var imgPath = "<img src='"+imageArray[rand]+"' alt='heder' border='0' align='absmiddle' />";
document.getElementById("image").innerHTML = imgPath;
}
doIt();
and the body portion of the markup could look like so:
HTML Code:
<body>
<div id="image"></div>
<br>
<br>
<br>
Other texts
<br>
<br>
<br>
more content
<script src="some.js" type="text/javascript"></script>
</body>
Bookmarks