http://javascript.about.com/library/weekly/aa122703a.htm
That has a little bit of infor on it. I will look around for some better resources, but that should get the point acrossed.
http://javascript.about.com/library/weekly/aa122703a.htm
That has a little bit of infor on it. I will look around for some better resources, but that should get the point acrossed.
Hi,
I'd choose document.location in this case, but using the header function should work anyways. Using a while loop with sleep can cause troubles with the max_execution_time php setting.
<?PHP
// insert code that starts session and does the other stuff.
$newmessage = 0;
$header = "thisscript.php";
$testa = "SELECT * FROM messages WHERE session = '$session' AND time > '$timestamp'";
$testb = mysql_query($testa, $link) or die(mysql_error());
$newmessage=mysql_numrows($testb);
sleep(1);
if ($newmessage != 0)
$header = "http://www.domain.com";
header("Location: $header";
exit;
?>
With javascript you can do the same, e.g.
<html>
<head>
<script language="JavaScript">
document.location.replace("http://www.domain.com");
</script>
</head>
<body>
</body>
</html>
Thomas
Hi, thanks for all the help so far.
<?PHP
// insert code that starts session and does the other stuff.$newmessage = 0;
$testa = "SELECT * FROM messages WHERE session = '$session' AND time > '$timestamp'";
$testb = mysql_query($testa, $link) or die(mysql_error());
$newmessage=mysql_numrows($testb);
sleep(1);
if ($newmessage != 0)<script language="JavaScript">
window.location.reload();
</script>exit;
?>
Is that right for the javascript way? I dont see how this loops?
Thanks,
Hi,
please post a description of how that chat application works. Is the IFRAME the chat window ?
There might be several ways to solve the problem but I need to know more about the app.
One possible solution.
Use tables to print the chat submissions. You could use an infinite loop but that could lead to problems with the max_execution_time setting in php.ini.
Inside the (infinite) while loop check if someone submitted new data. If yes, print a new row of the table (or even a new table for each submission) and then use flush() to force the output.
Another solution could be to have another hidden frame or iframe that reloads itself every one second and updates the iframe by using JavaScript each time someone submitted new data.
Thomas
Thomas
Ok,
Basically, the chat page has two iframes on it. One is to send the message, which just puts the message into the database. The other iframe, simply displays all the messages in the database. The only part which should reload is the iframe displaying the messages. I quite like the sound of the hidden IFRAME, which refreshed the main IFRAME when a new message is available. I am unsure how you would go about this though.
Thanks,
Hi,
did you already think about using frames instead of iframes ? By using iframes you might run in troubles with several non IE browsers.
In a hidden frame you could load a script that just reloads every n seconds. That script checks if new data has been posted and if yes you can use javascript code to reload the main frame.
Like (in short)
if (new data exists) {
parent.frames['chatmainframe'].location.reload();
}
document.location.reload();
Thomas
The problem is though, i am using the trasparancy feature as its all mapped round an image.
Thanks,
Ok,
that makes using standard frames a little bit more complicated. I think it could be done with frames but that would be some work. At least you would have to cut the image into several parts.
Did you already try to use a hidden frame ?
Thomas
Hi,
I am giving it a go with the hidden IFRAME now. I am unsure how to do this though. The IFRAMES are all setup, but I do not no how to make the page to check if a new message has been left as once its refreshed it would loose its value for $timestamp
Thanks,
Hi,
I think I have found a way of doing it. Can you just see if any think is wrong with:
if ($timestamp < $latesttime) {
print "<script type=\"text/javascript\">";
print "parent.frames['mainchat'].location.reload();";
print "</script>";
}
Thanks,
Hi,
first of all you should make sure that you don't print just the javascript code but a complete page including <html>...</html>.
Another point is that if you just print that javascript the hidden
Second, you need to make sure that the hidden script itself reloads and doesn't stop.
Put
<script language="JavaScript">
document.location.reload();
</script>
just after the first javascript.
Third, you can update the timestamp value to the new value after doing the reload on the main frame and store it in the session. Use the timestamp stored in the session to check if new data has been submitted.
Thomas
Hi,
I have pretty much got this sorted now. Can you see why this wouldnt work though:
<?php
header( 'refresh: 1' );
print "<HTML>";
print "<BODY>";
print "<script type=\"text/javascript\">";
print "parent.frames[\'mainchat\'].location.reload()\;";
print "</script>";
print "</BODY>";
print "</HTML>";
?>
Thanks,
Hi,
I have now fixed this, thanks for all your help, its much appreciated
Hi,
glad to hear that
Please mark this thread resolved if there are no questions remaining.
Thomas