Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

multiple random images

Posted on 1997-01-24
1
Medium Priority
?
354 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 400 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
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…
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
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.
Suggested Courses

610 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