Results 1 to 9 of 9
Thread: refresh/reload window every 5sec
-
05-07-2004, 04:45 PM #1Junior Guru Wannabe
- 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
-
05-07-2004, 04:59 PM #2Junior Guru Wannabe
- Join Date
- Mar 2004
- Posts
- 58
Turn off the sound in your control panel - that's the only way I know!
-
05-07-2004, 05:31 PM #3Web Hosting Guru
- Join Date
- May 2004
- Posts
- 305
if you fancy having your project attached to the GPL, download a copy of Help Center Live and see how ive done it there
-
05-08-2004, 04:17 AM #4Junior Guru Wannabe
- Join Date
- Jan 2004
- Posts
- 60
I don't understand much of your code I'm afraid your script is too extensive
-
05-08-2004, 06:02 AM #5Web Hosting Guru
- Join Date
- May 2004
- Posts
- 305
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
?>
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);
?>
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>
-
05-08-2004, 08:50 AM #6Junior Guru Wannabe
- 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);
?>
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
Thanks,
Cedric
-
05-08-2004, 09:17 AM #7Junior Guru Wannabe
- 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
-
05-08-2004, 10:56 AM #8Web Hosting Guru
- Join Date
- May 2004
- Posts
- 305
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
-
05-08-2004, 11:00 AM #9Junior Guru Wannabe
- 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