using Javascript for a real time chat program
Moderator: General Moderators
using Javascript for a real time chat program
Just wondering if anyone knows any (very) simple code to check if a file on the server has been updated since the page loaded ... and if so, get the filecontents into a php variable.
I don't know any Javascript, and the constant refresh for a purely php webchat can annoy some ppl.
eg : http://www.cse.unsw.edu.au/~elip/chat
so wondering if this can be done in real time and without constantly refreshing the browser.
Cheers
I don't know any Javascript, and the constant refresh for a purely php webchat can annoy some ppl.
eg : http://www.cse.unsw.edu.au/~elip/chat
so wondering if this can be done in real time and without constantly refreshing the browser.
Cheers
-
jollyjumper
- Forum Contributor
- Posts: 107
- Joined: Sat Jan 25, 2003 11:03 am
Hi Yogi,
I would make a frameset with 3 frames:
1. Frame with the content, and the content could be a textbox for input and a textarea for incoming text from other users.
2. Hidden frame(give value 0 in a frameset to a frame and you won't see it) where you can submit the user input to.
3. Hidden frame which you can refresh every couple of seconds. In this page you can use javascript to update the content of the textarea in your content area.
Hope this gives you an idea.
Greetz Jolly.
I would make a frameset with 3 frames:
1. Frame with the content, and the content could be a textbox for input and a textarea for incoming text from other users.
2. Hidden frame(give value 0 in a frameset to a frame and you won't see it) where you can submit the user input to.
3. Hidden frame which you can refresh every couple of seconds. In this page you can use javascript to update the content of the textarea in your content area.
Hope this gives you an idea.
Greetz Jolly.
I pretty much have most of that.
Because it currently does that ..
I am trying to avoid the frequent and very noticeable refresh that I get at http://www.cse.unsw.edu.au/~elip/chat/
I thought javascript may be able to help with that.
But I don't know any javascript at all .. so I may be wrong ??
Does this mean that even with javascript I have to have the browser refresh every few seconds ?"Hidden frame which you can refresh every couple of seconds. In this page you can use javascript to update the content of the textarea in your content area. "
Because it currently does that ..
I am trying to avoid the frequent and very noticeable refresh that I get at http://www.cse.unsw.edu.au/~elip/chat/
I thought javascript may be able to help with that.
But I don't know any javascript at all .. so I may be wrong ??
-
jollyjumper
- Forum Contributor
- Posts: 107
- Joined: Sat Jan 25, 2003 11:03 am
Hi Yogi,
I've checked the chatbox you we're talking about, and my first impression was that it is refreshing the content page.
With having a hidden frame which does the refreshing you avoid the flickering of the screen.
I'll give a simple example:
make two visible frames, let's say rows=*,100.
name the first one contentFrame
name the second one inputFrame.
in the contentFrame page you make a form with the name testform and within the form you make a textarea with the name textContent.
in the inputFrame page you make a form(doesn't need a name, but you may give one) and within the form you make a textbox with the name textInput and a button.
Put this line within the onclick event of the button:
parent.frames['contentFrame'].forms['testform'].textContent.value += this.form.textInput.value;
When you open the frameset you'll see a textarea at the top of your screen and a textbox with button at the bottom. Type someting in the textbox at the bottom and click the button. The value you've typed should appear in the textarea at the top.
It's not exactly what you are trying to accomplish but it's the same principle. The lowerframe is going to be the hidden frame which refreshes every couple of seconds and fills the textarea like the way the onclick event of the button does.
Good luck.
Greetz Jolly.
I've checked the chatbox you we're talking about, and my first impression was that it is refreshing the content page.
With having a hidden frame which does the refreshing you avoid the flickering of the screen.
I'll give a simple example:
make two visible frames, let's say rows=*,100.
name the first one contentFrame
name the second one inputFrame.
in the contentFrame page you make a form with the name testform and within the form you make a textarea with the name textContent.
in the inputFrame page you make a form(doesn't need a name, but you may give one) and within the form you make a textbox with the name textInput and a button.
Put this line within the onclick event of the button:
parent.frames['contentFrame'].forms['testform'].textContent.value += this.form.textInput.value;
When you open the frameset you'll see a textarea at the top of your screen and a textbox with button at the bottom. Type someting in the textbox at the bottom and click the button. The value you've typed should appear in the textarea at the top.
It's not exactly what you are trying to accomplish but it's the same principle. The lowerframe is going to be the hidden frame which refreshes every couple of seconds and fills the textarea like the way the onclick event of the button does.
Good luck.
Greetz Jolly.
Thanx for the help Jolly.
The thing I am more concerned about is where a user has posted a message and I need it to display in all users browsers in closer to real time
I could do this by refreshing every second .. but that'd get more annoying
What you've said, adds the users message in his own browser (I think), but I need it displayed in all browsers connected to the server and using this script ... preferable updated every second .. minus the click of the browser every second.
I don't know anything about javascript .. so this may not be possible ?
Because it needs to get the info from the server every second to check for updates.
Cheers,
Eli
The thing I am more concerned about is where a user has posted a message and I need it to display in all users browsers in closer to real time
I could do this by refreshing every second .. but that'd get more annoying
What you've said, adds the users message in his own browser (I think), but I need it displayed in all browsers connected to the server and using this script ... preferable updated every second .. minus the click of the browser every second.
I don't know anything about javascript .. so this may not be possible ?
Because it needs to get the info from the server every second to check for updates.
Cheers,
Eli
-
jollyjumper
- Forum Contributor
- Posts: 107
- Joined: Sat Jan 25, 2003 11:03 am
Ah yes the browser click, stupid anoying feature.
I'm afraid I can't help you with that, because I don't know how to get it away.
What maybe could be your answer is flash. I don't how formiliar you are with flash and action script, but if you are this could be a possibility.
You can use a hidden flash object to check the data at server every few seconds, and parse the data from the flash object to html with javascript. It's a more complicated way for sure, but I believe this is a sollution to avoid the click.
I have to tell you though that communication between flash en javascript is not possible on Internet Explorer on the Macintosh.
But as far as I know it is not possible to avoid the click sound with javascript.
As for the example I explained to you, it is indeed to show the users own input in another frame, but you can place the input by other users in the method, if you constantly refresh a hidden page which runs the javascript code which in the example was behind the onclick event of the button then the textarea box will update with new values.
Greetz Jolly.
I'm afraid I can't help you with that, because I don't know how to get it away.
What maybe could be your answer is flash. I don't how formiliar you are with flash and action script, but if you are this could be a possibility.
You can use a hidden flash object to check the data at server every few seconds, and parse the data from the flash object to html with javascript. It's a more complicated way for sure, but I believe this is a sollution to avoid the click.
I have to tell you though that communication between flash en javascript is not possible on Internet Explorer on the Macintosh.
But as far as I know it is not possible to avoid the click sound with javascript.
As for the example I explained to you, it is indeed to show the users own input in another frame, but you can place the input by other users in the method, if you constantly refresh a hidden page which runs the javascript code which in the example was behind the onclick event of the button then the textarea box will update with new values.
Greetz Jolly.
Thanx very much for the help and info Jolly.
btw .. I don't suppose you know of a good online tutorial for beginners for javasctipt.
I know programming in general (perl/CGI, php, C/C++, Java, and a couple of lesser known ones) .... but just haven't had ane experience with javascript.
Also, a forum that is as active with js as this one is with php would be great if you knew any.
Cheers
btw .. I don't suppose you know of a good online tutorial for beginners for javasctipt.
I know programming in general (perl/CGI, php, C/C++, Java, and a couple of lesser known ones) .... but just haven't had ane experience with javascript.
Also, a forum that is as active with js as this one is with php would be great if you knew any.
Cheers
the MAIN difference between PHP and JavaScript is that the first is Server-Oriented and the other is Client-Oriented.
you cannot make a forum with a client-sided script because it has a one-way(server->client) connection with the server from which every user loads the page. you MUST use a server oriented programming language and some sort of database (to store the messages that the script will display) in order to make a forum.
you cannot make a forum with a client-sided script because it has a one-way(server->client) connection with the server from which every user loads the page. you MUST use a server oriented programming language and some sort of database (to store the messages that the script will display) in order to make a forum.
-
jollyjumper
- Forum Contributor
- Posts: 107
- Joined: Sat Jan 25, 2003 11:03 am
I use groups.google.com a lot.
Also http://www.jsexamples.com is a great site for javascript.
And javascript.faqts.com is sometimes a great help to me..
For tutorials on javascript I would suggest you do a search on groups.google.com, I guess someone else has allready asked for something like that.
Greetz Jolly.
Also http://www.jsexamples.com is a great site for javascript.
And javascript.faqts.com is sometimes a great help to me..
For tutorials on javascript I would suggest you do a search on groups.google.com, I guess someone else has allready asked for something like that.
Greetz Jolly.
-
jollyjumper
- Forum Contributor
- Posts: 107
- Joined: Sat Jan 25, 2003 11:03 am
Just came across a website with forums, also one about javascript.
The url is: http://www.tutorialforums.com
Greetz Jolly.
The url is: http://www.tutorialforums.com
Greetz Jolly.