Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 157801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T10:34:07+00:00 2026-05-11T10:34:07+00:00

I’m a mostly-newbie Javascript’er and I’m trying it on a webpage which, upon pressing

  • 0

I’m a mostly-newbie Javascript’er and I’m trying it on a webpage which, upon pressing a button, pops up a window which shows a cyclic ‘movie’ with the images from the main window. From what I’ve tried Googling around I can sense I’m pretty close, but something is eluding me.

I know what follows results in two separate questions, which merit two separate posts. But I figure because both are related with the same problem/objective, maybe this belongs in a single (albeit long) post. So I hope the size of it doesn’t enfuriate people too much … 😉

Anyway, here’s a snapshot of what I think is the relevant code:

<html> <head> <script language='javascript'> function wait() {} function anim() {   var timeout; var next;   var popuptitle='Movie';   var main=parent;   var popup=parent.open('','',       'width='+main.document.images[0].width+',height='+(main.document.images[0].height+40)+       'toolbar=no,location=no,directories=no,status=no,'+       'menubar=no,scrollbars=no,copyhistory=no,resizable=no');   popup.document.write('<html><head><title>'+popuptitle+'</title></head><body>'+     '<p align='center'><img name='anim' width='100%' alt=''></p>'+     '<p align='center'><button name='close' onclick='javascript:window.close();'>Close</button></p>'+     '</body></html>');   /*while(true)*/   for(i=0; i<main.document.images.length; i++) {     next=main.document.images[i].src;     popup.document.images[0].src=next;     timeout=setTimeout('wait();',500);   } } </script> </head> <body><h1>Pictures + animation</h1> <p><button name='exec' onclick='javascript:anim();'>Animate (popup)</button></p> <p><img src='img1.jpg'></p> .... <p><img src='img16.jpg'></p> </body> </html> 

I typed/adapted this for relevancy; I hope I didn’t make any typos…

I’m working with the Debian Etch’s Iceweasel (Firefox 2.x rebrand); I haven’t tried this with other browsers. In Iceweasel, what happens is:

  1. The popup show up as is supposed to, but it seems the cycle goes straight to the last picture. setTimeout seems to have no effect in ‘pausing’ between pictures.
  2. The last picture is shown, and the popup’s status bar shows its progress bar midway, suggesting something is loading.

So my questions are:

  1. How exactly am I supposed to use the setTimeout call here? I’ve tried to make it call an ’empty’ function, so it works as a ‘pause’ in the cycle having the setTimeout(), where the cycle updates the popup single image from the main window’s images array.
  2. I find that, if I load the popup by loading the HTML code from an external file (anim.html), the statusbar seems to show from the ‘progress bar’ that the window keeps expecting a reload. I’m still going to try if it’s from somewhere else, but what I want to know if it is important/relevant that I load the HTML page from an external file with the window.open(), versus loading an empty window and doing a writeln to it to ‘write’ the HTML.
  3. I’ve commented the while(true) in the cycle, because otherwise the browser stops responding and the computer goes to 100% CPU. I could make an if in the for cycle to set the counter back to zero before the last item, but is there another ‘elegant’ or ‘more appropriate’ way to make this an infinite cycle — or does the while(true) do just fine?

I appretiate your comments in advance, and if possible a pointer to existing bibliography describing similar solutions.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T10:34:08+00:00Added an answer on May 11, 2026 at 10:34 am

    I do not think this means what you think it means:

    timeout=setTimeout('wait();',500); 

    Apparently, you’re trying to sleep() with this. That’s not how the JS timeouts work – this happens onclick in your code: you loop through the images array, immediately switch images from 0th to 1st … to last; also, on every switch, you say ‘run the wait() function, 500 ms from now’.

    window.setTimeout(foo,bar,baz) does this: it sets a timer for bar milliseconds and returns. Code execution continues with the next statement. After bar milliseconds, function foo(baz) is automagically called. The 3rd and following arguments for setTimeout are optional and will be passed to the function in 1st argument.

    What you could do:

    function anim() {    var timeout; var next;   var popuptitle='Movie';   var main=parent;   var popup=parent.open('','',       'width='+main.document.images[0].width+',height='+       (main.document.images[0].height+40)+       'toolbar=no,location=no,directories=no,status=no,'+       'menubar=no,scrollbars=no,copyhistory=no,resizable=no');   popup.document.write('<html><head><title>'+popuptitle+     '</title></head><body>'+     '<p align='center'><img name='anim' width='100%' alt=''></p>'+     '<p align='center'><button name='close' ' +      'onclick='javascript:window.close();'>Close</button></p>'+     '</body></html>');    // *changed below*   // start the animation with the 0th image   next_image(0,main.document.images,popup.document.images[0]); }  function next_image(index,source_image_array,target_image) {     // if not at end of array     if (source_image_array.length < index) {          next=source_image_array[index].src;         target_image.src=next;          // do this again in 500 ms with next image         window.setTimeout(next_image,500, index+1 ,                             source_image_array,target_image);     } } 

    This way, at the end of your anim() function, you call next_image(0), which sets the image to the 0th in array and sets a timer to call next_image(1) in 500 ms; when that happens, the image will be set to the 1st and a timer will be set to call next_image(2) in another 500 ms, and so on, until there are no more images in the array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 81k
  • Answers 82k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Is there a reason you want it in Cassini? You… May 11, 2026 at 4:35 pm
  • Editorial Team
    Editorial Team added an answer Try this instead: <services> <service name="WCFService.Service.CalculatorService" behaviorConfiguration="calculatorBehavior"> <host> <baseAddresses> <add… May 11, 2026 at 4:34 pm
  • Editorial Team
    Editorial Team added an answer My question has been answered here. Hi Nathan There's a… May 11, 2026 at 4:34 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I am currently running into a problem where an element is coming back from
Seemingly simple, but I cannot find anything relevant on the web. What is the
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.