Javascipting

Discussion in 'OT Technology' started by innerlogix, Oct 27, 2004.

  1. innerlogix

    innerlogix OT Supporter

    Joined:
    Aug 9, 2004
    Messages:
    48
    Likes Received:
    0
    I already posted this on the tutoring forum and nobody answered so i'm hoping I can get some replys from this one.

    I'm pretty new to javascripting and I need some help on the actual coding of something I need for a website. I'm tryin to create a site that has pop-up windows. As soon as you enter the site, a window will automatically pop-up with a central picture and then close after a few seconds spawning 2 more windows. This will keep on happening unless you click on the image in the window in which case the script which automatically closes the same popped-up window will cease to function and you can close it without any problems.

    Now for the technical parts, I already talked to someone about this who told me that I should use IF statements for this. The IF statement will basically say IF N=1 then terminate this part (which is the automatic close and pop-up thing) of the code. He told me that when you click on the image, you should make it so that it changes the variable I guess on the onclick function. The way that the pop up works is that I have a code which uses the onunload command to pop-up 2 new windows as soon as the original window closes. I also have a code which closes the window after a few seconds.

    I don't really have any experience in creating IF statements and such and need help with the coding.

    Any help would be useful:)
     
  2. ez4me2c3d

    ez4me2c3d Guest

    i almost considered helping you but it sounds like you're an annoyance
     
  3. Aimless

    Aimless Resident drunkey

    Joined:
    Nov 5, 2001
    Messages:
    2,534
    Likes Received:
    0
    Location:
    Wisconsin
    Help == false
     
  4. innerlogix

    innerlogix OT Supporter

    Joined:
    Aug 9, 2004
    Messages:
    48
    Likes Received:
    0
    no you don't understand, this is for a university art website, I'm a design student...

    I can even show you my project outline page if you want but I need the pop-ups as part of one of my pages...
     
  5. innerlogix

    innerlogix OT Supporter

    Joined:
    Aug 9, 2004
    Messages:
    48
    Likes Received:
    0
    i'm not a new user at all, I just don't post much on OT
    i've actually been a member for more than a year and had to remake my account because of the forums cleenup thing a while back...
     
  6. Jaycee0521

    Jaycee0521 New Member

    Joined:
    Jul 15, 2004
    Messages:
    64
    Likes Received:
    0
    dont quite get what youre trying to say. anyway... you dont need an if statement... i think you need a while loop...

    its gonna be something like

    numofwin = 1

    while(image not clicked)
    {
    sleep(2 seconds)
    close window
    open new window(numofwin)
    numofwin*=2
    }

    where numofwin is the number of windows to open..

    something like that... hope that helped
     
  7. innerlogix

    innerlogix OT Supporter

    Joined:
    Aug 9, 2004
    Messages:
    48
    Likes Received:
    0
    thnx alot, I ended up using an FI statement but incorporated your idea into it.
     
  8. innerlogix

    innerlogix OT Supporter

    Joined:
    Aug 9, 2004
    Messages:
    48
    Likes Received:
    0
    So basically I've got it down except for a small problem. iIve gotten the window to popup, then close by itself and then to popup 2 windows. The trouble i'm having is that after the first window closes and the first 2 windows popup, it won't do it again the second time. It should technically grow exponentially but it only opens 1 new window for each old window. So there is constantly only 2 windows when there should be more.

    here is the code i have so far and its a pretty simple if statement. I'd be greatful for any help fixing this small problem :)

    Code:
    	   
    var n = 1;
    	   
    	   var o;
    	   
     function opener() {
      o = window.setTimeout('window.close()','5000')
     }
     
     function closer()
     {
       if (n==1)
       {
    	window1 = window.open('loop.html','test1','width=200, height=200' ); 
      window2 = window.open('loop.html','test1','width=200, height=200' )
     
       
    	}
    	 else {
    	window.clearTimeout(o);
    	}
    } 
     
     
  9. Jaycee0521

    Jaycee0521 New Member

    Joined:
    Jul 15, 2004
    Messages:
    64
    Likes Received:
    0
    ok... what happens when your n increases? it will do that clearTimeout thing... sorry but i dont have any idea what that function does. it seems like it will only pop up two whenever n=1. does it ever increase?

    can i see the code that actually calls these functions?
     
  10. innerlogix

    innerlogix OT Supporter

    Joined:
    Aug 9, 2004
    Messages:
    48
    Likes Received:
    0
    alright, lemmie try to re explain. so the first thing this function does is close the window which then automatically triggers the if statement (because of the unonload) where it pops up the same page in 2 new windows. now if you click on the picture (black.gif) it will make n= 0. This will stop the countdown and terminate the unonload command. So there will be no more popups. I basically got all of this to work. The problem I'm having now is whenever I let this run, it will run perfectly the first round where the window will close and there will be 2 popups. But in the second time, there should be 2 new windows for each window (which should be 4) when both of them close down. This doesn't happen and only 2 windows in total popup. The windows should start growing exponentially but doesn't for some reason.

    Here is the code:

    Code:
     
    <BODY onunload="closer()" onLoad="opener()">
       <SCRIPT type="text/javascript">
    	   var n = 1;
    	   
    	   var o;
    	   
     function opener() {
      o = window.setTimeout('window.close()','5000')
     }
     
     function closer()
     {
       if (n==1)
       {
    	w1 = window.open('loop.html','test1','width=200, height=200' ); 
      w2 = window.open('loop.html','test2','width=200, height=200' )
     
       
    	}
    	 else {
    	window.clearTimeout(o);
    	}
    } 
     
       </SCRIPT>
    </BODY>
    <a href="javascript:n=0;" ><img src="black.gif"></a> 
     
  11. Jaycee0521

    Jaycee0521 New Member

    Joined:
    Jul 15, 2004
    Messages:
    64
    Likes Received:
    0
    not sure how that last line works. anyway... hmm... i'll try the code out sometime today if im not too busy. been very busy lately.
     
  12. Jaycee0521

    Jaycee0521 New Member

    Joined:
    Jul 15, 2004
    Messages:
    64
    Likes Received:
    0
    oh got how it works. ill try it out later and fix it for you if i can
     

Share This Page