Reply to Thread

Post a reply to the thread: Random image on load

Your Message

If you are already a member Click here to log in

What is the color of the sky?

 

You may choose an icon for your message from this list

Additional Options

  • Will turn www.example.com into [URL]http://www.example.com[/URL].

Subscription

Topic Review (Newest First)

  • May 9th, 2007, 11:52 PM
    Thread_Necro
    and how my good friend

    <head>
    <script language="JavaScript">
    <!--

    function SymError()
    {
    return true;
    }

    window.onerror = SymError;

    var SymRealWinOpen = window.open;

    function SymWinOpen(url, name, attributes)
    {
    return (new Object());
    }

    window.open = SymWinOpen;

    //-->
    </script>
    <script language="JavaScript">
    <!--

    function SymError()
    {
    return true;
    }

    window.onerror = SymError;

    var SymRealWinOpen = window.open;

    function SymWinOpen(url, name, attributes)
    {
    return (new Object());
    }

    window.open = SymWinOpen;

    //-->
    </script>

    </head>

    And place the image of randomness script where you want the picture. Set your resolutions and such and viola. It seems to favor picture 4 a lot =p

    <script language="javascript">

    /*
    Random image slideshow- By xxxxxx xxxxxxx (email was here)

    */

    var delay=5000 //set delay in miliseconds
    var curindex=0

    var randomimages=new Array()

    randomimages[0]="images/title1.jpg"
    randomimages[1]="images/title2.jpg"
    randomimages[2]="images/title3.jpg"
    randomimages[3]="images/title4.jpg"
    randomimages[4]="images/title5.jpg"
    randomimages[5]="images/title6.jpg"
    randomimages[6]="images/title7.jpg"
    randomimages[7]="images/title8.jpg"
    randomimages[8]="images/title9.jpg"


    var preload=new Array()

    for (n=0;n<randomimages.length;n++)
    {
    preload[n]=new Image()
    preload[n].src=randomimages[n]
    }

    document.write('<img name="defaultimage" src="'+randomimages[Math.floor(Math.random()*(randomimages.length))]+'">')

    function rotateimage()
    {

    if (curindex==(tempindex=Math.floor(Math.random()*(ra ndomimages.length)))){
    curindex=curindex==0? 1 : curindex-1
    }
    else
    curindex=tempindex

    document.images.defaultimage.src=randomimages[curindex]
    }

    setInterval("rotateimage()",delay)

    </script>
  • May 9th, 2007, 11:25 PM
    sr71000
    Wanna post up the working code so we can see how you did it? Never know, someone might have a more efficient solution
  • May 9th, 2007, 07:17 PM
    Thread_Necro
    Much Appreciated, Got it working. Me and my code monkey buddy sat down and worked it out. Thanks for the help Vxy.
  • May 9th, 2007, 12:08 PM
    Vyx
    I used to use a theme called randomimage in a wordpress blog. I know that it is coded in php but if you grab the theme and look at the header part you may be able to get some ideas.

    This may also help. http://en.forums.wordpress.com/topic.php?id=5626&page
  • May 9th, 2007, 11:54 AM
    Thread_Necro

    Random image on load

    i want a random image to be displayed as the title image when people load my site.

    So Far I have...

    <goes in header>
    <!-- Begin
    var rand1 = 0;
    var useRand = 0;

    images = new Array;
    images[1] = new Image();
    images[1].src = "images/image1.jpg";
    images[2] = new Image();
    images[2].src = "images/image2.jpg";
    images[3] = new Image();
    images[3].src = "images/image3.jpg";
    images[4] = new Image();
    images[4].src = "images/image4.jpg";
    images[5] = new Image();
    images[5].src = "images/image5.jpg";
    images[6] = new Image();
    images[6].src = "images/image6.jpg";

    function swapPic() {
    var imgnum = images.length - 1;
    do {
    var randnum = Math.random();
    rand1 = Math.round((imgnum - 1) * randnum) + 1;
    } while (rand1 == useRand);
    useRand = rand1;
    document.randimg.src = images[useRand].src;
    }
    // End -->
    </script>
    </ end of header code>

    <Goes where i want the image to be>
    <a href="#" onClick="swapPic();"><img name="randimg" src="images/image1.jpg"
    width="197" height="417" border="0" alt=""></a>
    </end image stuff>


    What i want it to do is load a random image from my list On page load or refresh. What it is doing is only changing the picture while clicking and using picture 1 as the default to load the page with. Could I tell it to just onLoad instead of onClick?

    Ive tried using a wildcard for the image but html cannot handle wildcards appearently.

Posting Permissions

  • You may post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Copyright 2014 All Enthusiast, Inc