Closed Thread Icon

Topic awaiting preservation: New window (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=8339" title="Pages that link to Topic awaiting preservation: New window (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: New window <span class="small">(Page 1 of 1)</span>\

 
danica
Bipolar (III) Inmate

From:
Insane since: Oct 2002

posted posted 10-08-2002 17:24

I know :
window.oepn([sURL] [, sName] [, sFeatures] [, bReplace])
Opens a new window and loads the document specified by a given URL, but is there a way to open the same htm file in the new window and load a different image in this file randomly




Dracusis
Maniac (V) Inmate

From: Brisbane, Australia
Insane since: Apr 2001

posted posted 10-08-2002 17:51

I'm a littel confused as to what your trying to do.

So you want to open a new window from say page.html

But in that window you want to load the same page.html file, but you want an image in page.html to be displayed randomly from a list of images?

Yes, it's possible, but I should point out that this could cause some really confusing problems. Having a page that opens a new window with the same page means the use could end up opening that page in hundreds of different windows.

Anyways, if you still want to do this you'll need to do a couple of things for the random image display.

Firstly you'll need to name your <img> tag with a name="whatever" and an id="whatever", like so:
<img id="image1" name="image1" height="100" width="200" src="images/myDog.jog" />

Then you'll need to make a list of the images you'l want to random;y display in it's place. You'll need to make an array of strings that contain the path to those images:

randomImage = new Array()
randomImage[0] = "images/myDog.jpg"
randomImage[1] = "images/myCat.jpg"
randomImage[2] = "images/myChicken.jpg"
randomImage[3] = "images/myGoose.jpg"
randomImage[4] = "images/mySwampBear.jpg"

Then you'll need to generate a random number for that array:
randomNumber = Math.round(Math.random()*randomImage.length)

Then you'll need to set that random image to the <img> tag:
document.images("image1").src = randomImage[randomNumber]

Put it all in a function and call it on page load, which should look something like this when your finished:

<html>
<head><title>My Page</title>
<script type="text/css">
onload = setRandomImage

randomImage = new Array()
randomImage[0] = "images/myDog.jpg"
randomImage[1] = "images/myCat.jpg"
randomImage[2] = "images/myChicken.jpg"
randomImage[3] = "images/myGoose.jpg"
randomImage[4] = "images/mySwampBear.jpg"

function setRandomImage() {
randomNumber = Math.round(Math.random()*randomImage.length)
document.images("image1").src = randomImage[randomNumber]
}
</head>
<body>

<img id="image1" name="image1" height="100" width="200" src="images/myDog.jog" />

</body>
</html>

danica
Bipolar (III) Inmate

From:
Insane since: Oct 2002

posted posted 10-08-2002 20:21

Thanks a lot

« BackwardsOnwards »

Show Forum Drop Down Menu