Go to new page at the end of my function script

Discussion in 'Javascript' started by Tony, Jul 31, 2006.

  1. Tony

    Tony Guest

    I have a function that loops through a set of images but at the end of
    the loop I need the page to go to a new location. Does anyone know how
    force my page to go there.

    This is what I am thinking

    function animateThenGo()
    loopimages;
    location.href "mypage.htm"

    anything that might get me started would be great.
    Tony, Jul 31, 2006
    #1
    1. Advertising

  2. Tony

    VK Guest

    Tony wrote:
    > I have a function that loops through a set of images but at the end of
    > the loop I need the page to go to a new location. Does anyone know how
    > force my page to go there.
    >
    > This is what I am thinking
    >
    > function animateThenGo()
    > loopimages;
    > location.href "mypage.htm"
    >
    > anything that might get me started would be great.


    JavaScript doesn't have commands like "pause" or "sleep" or "resume" or
    so. So with your approach the script will loop all images momentarly
    and load new page. You need a timer here.
    ....
    function loopImages() {
    if (condition) {
    // swap image
    setTimeout('loopImages()', delay);
    }
    else {
    location.href = 'mypage.html';
    }
    }

    window.onload = loopImages;
    ....

    condition, swap image routine and the desired delay (in ms) are left
    for you.
    VK, Jul 31, 2006
    #2
    1. Advertising

  3. Tony

    Randy Webb Guest

    VK said the following on 7/31/2006 12:21 PM:
    > Tony wrote:
    >> I have a function that loops through a set of images but at the end of
    >> the loop I need the page to go to a new location. Does anyone know how
    >> force my page to go there.
    >>
    >> This is what I am thinking
    >>
    >> function animateThenGo()
    >> loopimages;
    >> location.href "mypage.htm"
    >>
    >> anything that might get me started would be great.


    What you have is a good start, other than the missing = sign after
    location.href

    > JavaScript doesn't have commands like "pause" or "sleep" or "resume" or
    > so. So with your approach the script will loop all images momentarly
    > and load new page. You need a timer here.


    Yours won't do any better.

    > function loopImages() {
    > if (condition) {
    > // swap image
    > setTimeout('loopImages()', delay);
    > }
    > else {
    > location.href = 'mypage.html';
    > }
    > }
    > window.onload = loopImages;


    There is no need for recursion there. None at all.

    > condition, swap image routine and the desired delay (in ms) are left
    > for you.


    And a proper logic sequence as well?

    --
    Randy
    comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
    Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
    Randy Webb, Jul 31, 2006
    #3
  4. Tony

    VK Guest

    Randy Webb wrote:
    > > function loopImages() {
    > > if (condition) {
    > > // swap image
    > > setTimeout('loopImages()', delay);
    > > }
    > > else {
    > > location.href = 'mypage.html';
    > > }
    > > }
    > > window.onload = loopImages;

    >
    > There is no need for recursion there. None at all.


    Where did you see any recursion here? loopImages sets timer, but it
    doesn't call itself in the same execution context.
    If you have a better idea how to make a timed slideshow without timers
    I would like to see it. Something like to try to check the processor
    speed and set 10,000-1,000,000 sin-cos calculation loops? ;-)

    > And a proper logic sequence as well?


    I will be glad to further comment the logic for OP and anyone else if
    asked.
    VK, Aug 1, 2006
    #4
  5. Tony

    Tony Guest

    I have been trying to adapt what you said to this bit of (out of my
    league) code.
    Would you mind taking a look at it and telling where to insert the if
    statement you gave to that will make the page go to the new page after
    the images have looped once.

    I will be applying this to an imag map next so I can't use the page
    load to start the animation. It must start when the user clicks on the
    map.

    Thanks

    <html>
    <head>
    <SCRIPT>
    function ImageAnimator (imgName, imgURLs, spd) {
    this.id = ImageAnimator.cnt;
    ImageAnimator.elements[ImageAnimator.cnt++] = this;
    this.imgName = imgName;
    this.imgURLs = imgURLs;
    this.spd = spd ? spd : 500;
    this.images = new Array(this.imgURLs.length);
    for (var i = 0; i < this.imgURLs.length; i++) {
    this.images = new Image();
    this.images.src = this.imgURLs;
    }
    }
    function ImageAnimator_play (up) {
    if (this.tid)
    clearTimeout(this.tid);
    this.up = up || typeof up == 'undefined' ? true : false;
    if (this.up)
    this.cnt = 0;
    else
    this.cnt--;
    if (!this.image)
    this.image = document[this.imgName];
    if (this.image) {
    if (this.up)
    this.animateUp();
    else
    this.animateDown();
    }
    }
    ImageAnimator.prototype.play = ImageAnimator_play;
    function ImageAnimator_animateUp () {
    this.image.src = this.images[this.cnt].src;
    this.cnt++;
    if (this.cnt < this.imgURLs.length) {
    this.tid = setTimeout('ImageAnimator.elements[' + this.id
    + '].animateUp()', this.spd);
    }
    else
    this.cnt--;
    }
    ImageAnimator.prototype.animateUp = ImageAnimator_animateUp;
    function ImageAnimator_animateDown () {
    this.image.src = this.images[this.cnt].src;
    this.cnt--;
    if (this.cnt >= 0 && this.cnt < this.imgURLs.length) {
    this.tid = setTimeout('ImageAnimator.elements[' + this.id
    + '].animateDown()', this.spd);
    }
    else
    this.cnt = 0;
    }
    ImageAnimator.prototype.animateDown = ImageAnimator_animateDown;
    ImageAnimator.cnt = 0;
    ImageAnimator.elements = new Array();
    </SCRIPT>
    <SCRIPT>
    var anImageAnimator =
    new ImageAnimator (
    'anImage',
    new Array ('images/Entrance.gif',
    'images/EntranceTurn1.gif',
    'images/EntranceTurn2.gif',
    'images/EntranceTurn3.gif',
    'images/EntranceTurn4.gif',
    'images/EntranceTurn5.gif',
    'images/EntranceTurn6.gif',
    'images/EntranceTurn7.gif',
    'images/main.gif'),
    50
    );
    </SCRIPT>

    <title></title>
    <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
    <meta name="vs_targetSchema"
    content="http://schemas.microsoft.com/intellisense/ie5">

    </head>
    <body bottomMargin="0" leftMargin="0" topMargin="0" rightMargin="0">

    <map name="btnMap">
    <area href="javascript: void 0" onclick="anImageAnimator.play(true)"
    shape="rect" coords="41, 35, 133, 68">
    </map>
    <IMG NAME="anImage" SRC="images/Entrance.gif" BORDER="0"
    usemap="#btnMap">

    </body>
    </html>
    Tony, Aug 6, 2006
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Neo Geshel
    Replies:
    2
    Views:
    3,573
    Versteijn
    Aug 18, 2004
  2. William
    Replies:
    2
    Views:
    1,714
    Kevin Spencer
    Jun 1, 2005
  3. Replies:
    2
    Views:
    346
  4. lovecreatesbeauty

    The end of C-like script languages - C script with TCC

    lovecreatesbeauty, May 20, 2011, in forum: C Programming
    Replies:
    19
    Views:
    1,304
    Malcolm McLean
    Jun 19, 2011
  5. Jimmy
    Replies:
    3
    Views:
    315
    J. J. Farrell
    Sep 9, 2011
Loading...

Share This Page