Solved

multiple random images

Posted on 1997-01-24
1
326 Views
Last Modified: 2013-12-25
can i have several images strung to a page so that every time the page is accessed it will load a different image randomly? As in if someone visited my page several times they would see a different logo each time.
0
Comment
Question by:D.Murray
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
DocOzone earned 200 total points
ID: 1865377
Hi there D.Murray! Sure, you can do this using Javascript, but it will only work with the newest versions of Netscape (3.0 and 4.0). Presumably the next version of Internet Explorer will handle the "image" object in Jscript. Here's what you do...
   Inside your <head> tags, include this script...
-------
<SCRIPT LANGUAGE="JavaScript">
<!--I start and end every javascript section with traditional comments, just in case.

// First, avoid any browser but NS3, we'll use this statement at the start of every function
        if (navigator.userAgent.substring(0,9) == "Mozilla/3") {
// Now make the array called myimages
        myimages = new Array(4);
    for (m=0; m<=3; m++) {
    myimages[m] = new Image(); }
        myimages[0].src = "images/myimage1.jpeg";
        myimages[1].src = "images/myimage2.jpeg";
        myimages[2].src = "images/myimage3.jpeg";
        myimages[3].src = "images/myimage4.jpeg";  }
// End the array creation
 
// Here's a random image generator function.
       function randoscript() {
                if (navigator.userAgent.substring(0,9) == "Mozilla/3") {
                rando = Math.round( Math.random() * 3 );
                document.myimage.src = myimages[rando].src; }}
// This is the end of the random function.

// end scripts   -->
</SCRIPT>
-----------
Replace the calls for "myimageXXX.jpeg " with the path to your images. Note that all of these images should be the same size, or they will be re-sized to fit in the space of the first image. Now, in your HTML, place the first image, where our random image will go. You can fill this space with a blank dummy file if you'd like, but I'll do it with one of the files from the "myimage" series. Reference it like this...
---------
<A HREF="javascript: randoscript()"><img name="myimage" src="images/myimage1.jpeg"></A>
---------
I've put this inside an <a href> link so you can click on the image to load a new random image. You want it to pick a random image as it loads, so in your <body> tag, include this...
---------
<body onLoad="randoscript()">
---------
That's it. You can see this script in action at "http://www.ozones.com/~drozone/java-templates/index6.html"

Take care! Your pal,   -doc-

0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question