#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    UK
    Posts
    27
    Rep Power
    0

    Javascript DHTML Chat Room


    I am a bit of a beginner in this area, but does anybody know any good tutorials / code examples for a javascript based chat room? A good example of the type of chat room I am after can be found at www.collegeclub.com in the Instant Messenger Chat feature.

    Really, I am looking for any way to code an instant (fairly instant) internet chat room, WITHOUT java or using a HTML page created at the server and using a META Refresh tag.

    Any help or pointers to get me started would be great.

    Thanks,
    Benji.
  2. #2
  3. No Profile Picture
    The one who gets it done
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Location
    Madison, WI
    Posts
    395
    Rep Power
    13
    So you think you can do this with JavaScript? Hmmm. Interesting question. The crux is, information must get from the user to the server (somehow) so that it can then show up in the HTML for other users.

    Taking out Java, you are taking out any way of sending the information real-time.

    Taking out server-sides, you are taking out any way of getting information to the server.

    Someone correct me if I'm crazy, what you want to do is not possible. I hope I'm wrong.

    Why not just learn PHP or ASP?

    J
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    UK
    Posts
    27
    Rep Power
    0
    No, you are right. I didn't quite think this through properly.

    The way I have seen it done is clever, and makes it look like there is no refresh. The chat room is split into three frames, an invisible one that does all the refreshing and communication with the server, a middle one that shows the conversation, and a third which allows the user to send a message.

    The server db handles the conversation and the hidden frame gets any new comments from it. It then uses a javascript document.write to the conversation frame to make it look like the comment just 'appeared' without a server refresh. It is not realtime, but near enough and removes the flicker effect of the conversation page refreshing cos it never actually refreshes. Very clever and fooled me (not hard I know!!).

    The actual chat semantics can be handled with a server side lang, such as PHP (which I do know !), it was the front end I was concerned about.

    Thanks for the help anyway.
    Benji.
  6. #4
  7. No Profile Picture
    The one who gets it done
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Location
    Madison, WI
    Posts
    395
    Rep Power
    13
    In that case you could have the invisible frame be the PHP page, which could update once every 10 seconds (or whatever) with new text.

    You could have JS in the other frame check every 5 seconds or so, and send the new text to the conversation window...

    Just an idea.

    J
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2000
    Location
    UK
    Posts
    27
    Rep Power
    0
    I'll be looking at both ways I think. CollegeClub.com uses two invisible frames which handle both the sending and posting of messages to the chat room. When a message is typed and the SEND button pressed, JavaScript requests a page in the PostMessage invisible frame which sends the message. The message is also instantly written to the conversation frame and the text box is cleared ready for the next message.

    This creates the illusion (very well I think) of instant message delivery. Now to try and replicate it...

    Cheers,
    Benji.
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    1
    Rep Power
    0

    Javascript based chat forum?


    Hmmm strange you should ask that... I challenged myself to make a javascript based chat forum. But as you said you do need server side intervention such as with php, perl or vb.

    But there is another way to do it other than using an invisible frame. You can use DOM2 to create an object and set its source to a server side document. Such as a php page you can then parse information to and thro via the query string. Infact using this is the closest javascript chat device I know of. But if you do not already know DOM2 is only supported by NN6+ and IE5.5+.

    After all my work I actually finished my chat forum and named it minichat. Currently I am planing to recode it and therefore you cannot find it on the net (you might find other chat forums named minichat however which are not mine!). I wouldn' suggest using it as it is very buggy but you can find the first version of the code here: http://minichat.port5.com/Mini%20Chat%20v1.0.zip

    good luck,

    Adam

IMN logo majestic logo threadwatch logo seochat tools logo