Results 1 to 9 of 9
  1. #1
    Join Date
    Jan 2004
    Posts
    60

    refresh/reload window every 5sec

    Hello

    I'm creating a basic livesupport system for my site and I have a small problem: a page should be refreshed every 5 seconds. Site is in php.

    There are options like "meta refresh", "header refresh" "<script>window.setTimeout('changeurl();',2000); function changeurl(){window.location='test.php?test=bla'}</script>";", etc... But when I use these options I always hear an annoying sound when the page refreshes and this cannot be. Any ideas how to refresh a page silently?

    Thanks a lot!
    Cedric

  2. #2
    Turn off the sound in your control panel - that's the only way I know!

  3. #3
    if you fancy having your project attached to the GPL, download a copy of Help Center Live and see how ive done it there

  4. #4
    Join Date
    Jan 2004
    Posts
    60
    I don't understand much of your code I'm afraid your script is too extensive

  5. #5
    ok, I'll write you an example app. This is licensed under the GPL.


    so_how_do_i_do_it.php:
    PHP Code:
    <?php
        
    ///////////////////////////////////////////////////////////////////////////////
        // Copyright © 2003 Michael Bird. All Rights Reserved                        //
        //                                                                           //
        // This file is part of Help Center Live.                                    //
        //                                                                           //
        // Help Center Live is free software; you can redistribute it and/or modify  //
        // it under the terms of the GNU General Public License as published by      //
        // the Free Software Foundation; either version 2 of the License, or         //
        // (at your option) any later version.                                       //
        //                                                                           //
        // Help Center Live is distributed in the hope that it will be useful,       //
        // but WITHOUT ANY WARRANTY; without even the implied warranty of            //
        // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             //
        // GNU General Public License for more details.                              //
        //                                                                           //
        // You should have received a copy of the GNU General Public License         //
        // along with Help Center Live; if not, write to the Free Software           //
        // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA //
        ///////////////////////////////////////////////////////////////////////////////

        // Ok, now we dont want to hear any noises from the browser
        // because they get annoying.
        // To get over this, instead of refreshing the page, we are going
        // to refresh pretty much the only other thing that can refresh..
        // an image.

        // What you want to do is put all your code in a php file that checks
        // for any new messages
    ?>
    image.php:
    PHP Code:
    <?php
        
    ///////////////////////////////////////////////////////////////////////////////
        // Copyright © 2003 Michael Bird. All Rights Reserved                        //
        //                                                                           //
        // This file is part of Help Center Live.                                    //
        //                                                                           //
        // Help Center Live is free software; you can redistribute it and/or modify  //
        // it under the terms of the GNU General Public License as published by      //
        // the Free Software Foundation; either version 2 of the License, or         //
        // (at your option) any later version.                                       //
        //                                                                           //
        // Help Center Live is distributed in the hope that it will be useful,       //
        // but WITHOUT ANY WARRANTY; without even the implied warranty of            //
        // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             //
        // GNU General Public License for more details.                              //
        //                                                                           //
        // You should have received a copy of the GNU General Public License         //
        // along with Help Center Live; if not, write to the Free Software           //
        // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA //
        ///////////////////////////////////////////////////////////////////////////////

        // Put all of the code to check for messages here.
        // if there is a new message, it needs to call an image 2px x 2px in size
        // lets call that 2.gif
        // if there are no messages, call 1.gif 1px x 1px

        
    if($message == "there is a new message"){
            
    $image "/path/to/2.gif";
        }else{
            
    $image "/path/to/1.gif";
        }

        
    header("Content-type: image/gif");
        
    readfile($image);
    ?>
    message_checker.php
    PHP Code:
    <?php
        
    ///////////////////////////////////////////////////////////////////////////////
        // Copyright © 2003 Michael Bird. All Rights Reserved                        //
        //                                                                           //
        // This file is part of Help Center Live.                                    //
        //                                                                           //
        // Help Center Live is free software; you can redistribute it and/or modify  //
        // it under the terms of the GNU General Public License as published by      //
        // the Free Software Foundation; either version 2 of the License, or         //
        // (at your option) any later version.                                       //
        //                                                                           //
        // Help Center Live is distributed in the hope that it will be useful,       //
        // but WITHOUT ANY WARRANTY; without even the implied warranty of            //
        // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             //
        // GNU General Public License for more details.                              //
        //                                                                           //
        // You should have received a copy of the GNU General Public License         //
        // along with Help Center Live; if not, write to the Free Software           //
        // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA //
        ///////////////////////////////////////////////////////////////////////////////


        // In this file we want to include the image and check its size
        // to do this we use this javascript function
    ?>
    <script type="text/javascript" language="javascript">
    <!--
        var image = new Image();
        var time;
        var width = 0;

        function timer()
        {
            date = new Date();
            return date.getTime();
        }

        function check()
        {
            time = timer();
            if(width == 2){
                parent.window_that_needs_to_be_reloaded.location = "http://www.example.com/file.php";
            }
        }

        function reload()
        {
            image = new Image();
            image.src = "http://www.example.com/image.php";
            image.onload = check;
            setTimeout("reload();", 5000);
        }
    -->
    </script>
    I hope that helps you understand it better

  6. #6
    Join Date
    Jan 2004
    Posts
    60
    Hmm it doesn't work sorry but I don't know much about javascript.. yet your script looks great!



    PHP Code:
    <?php 
    //this is image.php (I've changed it a bit so the page should reload every time)
        
    $image "/images/2.gif"
        
    header("Content-type: image/gif"); 
        
    readfile($image); 
    ?>
    I have replaced parent.window_that_needs_to_be_reloaded.location = "http://www.example.com/file.php"; by document.write("test"); but it doesnt work (parent.. didn't work either)


    PHP Code:

    <?php 
    //this is file.php
        /////////////////////////////////////////////////////////////////////////////// 
        // Copyright © 2003 Michael Bird. All Rights Reserved                        // 
        //                                                                           // 
        // This file is part of Help Center Live.                                    // 
        //                                                                           // 
        // Help Center Live is free software; you can redistribute it and/or modify  // 
        // it under the terms of the GNU General Public License as published by      // 
        // the Free Software Foundation; either version 2 of the License, or         // 
        // (at your option) any later version.                                       // 
        //                                                                           // 
        // Help Center Live is distributed in the hope that it will be useful,       // 
        // but WITHOUT ANY WARRANTY; without even the implied warranty of            // 
        // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the             // 
        // GNU General Public License for more details.                              // 
        //                                                                           // 
        // You should have received a copy of the GNU General Public License         // 
        // along with Help Center Live; if not, write to the Free Software           // 
        // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA // 
        /////////////////////////////////////////////////////////////////////////////// 


        // In this file we want to include the image and check its size 
        // to do this we use this javascript function 





    ?> 
    <script type="text/javascript" language="javascript"> 
    <!-- 
        var image = new Image(); 
        var time; 
        var width = 0; 

        function timer() 
        { 
            date = new Date(); 
            return date.getTime(); 
        } 

        function check() 
        { 
            time = timer(); 
            if(width == 2){ 
                document.write("test"); 
            } 
        } 

        function reload() 
        { 
            image = new Image(); 
            image.src = "image.php"; 
            image.onload = check; 
            setTimeout("reload();", 1000); 
        } 
    --> 
    </script>

    sdffds
    Am I missing something, should I create an iframe in my file.php with the name "window_that_needs_to_be_reloaded" or should I add a <body "onload()"?


    Thanks,
    Cedric

  7. #7
    Join Date
    Jan 2004
    Posts
    60
    Btw I'm going to create the rest of the script entirely in php (unlike your script).. so I only need this piece of javascript to make the entire script work. Hope you can help me,

    Cedric

  8. #8
    hmm, if you dont know much about javascript i wouldnt recommend doing it my way. it is quite complicated

    the window that needs to be reloaded should contain php that pulls the new messages

  9. #9
    Join Date
    Jan 2004
    Posts
    60
    Well I can pull the messages out of the database via php, that isn't the problem. But you're probably right.. since I don't know much about javascript.

    cedric

Posting Permissions

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