Solved

multiple random images

Posted on 1997-01-24
1
332 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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

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

Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
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:
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.

738 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