SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Wizard
    Join Date
    Jan 2005
    Location
    blahblahblah
    Posts
    1,447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    open window, PHP loop, close window

    Hello,
    I have some experience in PHP but not at all in javascript. So sorry if my question seems very basic.
    Here is a dexcription of what I am trying to achieve.

    I'm building an app who will need to run a script as long as the user doesn't have this script stoped. Since cron jobs aren't available to me, I have chosen to go with an endless loop.

    It goes like this:
    PHP Code:
    while(1==1){
        
    //check if the user has stoped the script.
        //if not, keep on looping

    To start this action, I thought about opening a window, initiate the loop, close the window.

    How does it sound to you JS gurus?

    Here is the scenario. The user has clicked link. A window pops up. The script is initiated. The window closes itself.

    Script of the popup window:
    PHP Code:
    $i=1;
    while(
    1==1){
        
    //check if the user has stoped the script.
        //if not, keep on looping

        
    if($i==1){
            
    //javascript closes window
        
    }

        
    $i++

    Does it sound possible? Would it stop the script?

    Thanks in advance for your help

  2. #2
    SitePoint Addict NikoB's Avatar
    Join Date
    Nov 2005
    Location
    Austria
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you shouldnt work with an endless loop like this... it will block the browser. Use setTimeout instead...
    Code:
    var toclose = false;
    function yourFunc ()
    {
       // do whatever youn want
       .....
       if (toclose)
          window.close();
       else
         window.setTimeout("yourFunc()", 10000);
    }
    Corinis OpenSource Community & Content Management
    http://www.corinis.org

  3. #3
    SitePoint Wizard
    Join Date
    Jan 2005
    Location
    blahblahblah
    Posts
    1,447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello
    what would be the cleanest javscript code to close a window?

    <javascript>
    ...
    </javascript>

    ??


  4. #4
    SitePoint Addict NikoB's Avatar
    Join Date
    Nov 2005
    Location
    Austria
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    window.close();
    Corinis OpenSource Community & Content Management
    http://www.corinis.org

  5. #5
    SitePoint Wizard
    Join Date
    Jan 2005
    Location
    blahblahblah
    Posts
    1,447
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just this... no javascript tag before?

  6. #6
    SitePoint Addict NikoB's Avatar
    Join Date
    Nov 2005
    Location
    Austria
    Posts
    211
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code:
    <script>
    window.close();
    </script>
    Corinis OpenSource Community & Content Management
    http://www.corinis.org


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •