www.webdeveloper.com
Results 1 to 13 of 13

Thread: Mini Chat Room

  1. #1
    Join Date
    Oct 2008
    Posts
    16

    Exclamation Mini Chat Room

    Hi. I wanna make a javascript chatroom. it will have two frames. one will hold messages while the other will hold the message box. i will need scripts to make a text file on the fly on the server,update a message form to the text file and delete the file when done. if deleting is not possible the i just need the update the message to the text file or maybe html file for people 2 see. thanks

  2. #2
    Join Date
    Feb 2008
    Posts
    1,666
    You need server-side code to accomplish any of this.

  3. #3
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    Quote Originally Posted by MrNobody View Post
    You need server-side code to accomplish any of this.
    i disagree.

    trested on IIS (xp pro), and "Apache/2.0.63 (Unix) mod_bluestem/0.18 mod_jk/1.2.23 mod_ssl/2.0.63 OpenSSL/0.9.7d"
    don't forget to allow writes...

    tested in Ie6 and ff3.

    Code:
    <html>
    <head>
    <title>JS - IM</title>
    </head>
    
    <body onload="boot()">
    
    Log<br /><textarea rows='15' cols='80' id='body'></textarea>	
    
    <br />  Message: <input type='text'  id='message' value=''  />
    
    	<input type="button" value="Send" onclick="send()">
    
    
    <script  type="text/javascript" >
    
    function el(tid) {return document.getElementById(tid);}
    
        function aGet(turl, callback) {
            var XHRt =!window.XMLHttpRequest ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
            XHRt.open("GET", turl, true);
            XHRt.onreadystatechange =    function () {
      	      if (XHRt.readyState == 4 && XHRt.responseText) {
            	    callback(XHRt.responseText);
    	        }
        }
            XHRt.setRequestHeader("Content-Type", "text/html");
            XHRt.send("");
            return XHRt;
        }
    
    function IO(U, V) {
        var X = !window.XMLHttpRequest ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
        X.open(V ? 'PUT' : 'GET', U, !1);
        X.setRequestHeader('Content-Type', 'text/html')
        X.send(V ? V : '');
    return X.responseText;}
    
    
    var resp,bod,mess;
    
    function boot(){
    	pf= "im.tmp" //page file
    	resp="";
    	bod = el("body");
    	mess = el("message");
    	var tim=setInterval(check, 5000);
    }
    
    function incoming(text){
    	if(text!=resp){ resp = text; } else{ return;}
    	bod.value = bod.value + resp+"\n______________________\n"
    }
    
    function check(){
    	aGet(pf+"?"+(new Date).getTime(), incoming);
    }
    
    function send(){
      IO(pf, mess.value);
    }
    
     </script>
    </body>
    </html>

  4. #4
    Join Date
    Oct 2008
    Posts
    16
    how would i set it up

  5. #5
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    Quote Originally Posted by ickla10 View Post
    how would i set it up
    there's really nothing to setup.

    just save the code as chat.htm.

    enable write permissions for either the whole folder; or:

    create a new text file in the same folder as chat.htm
    rename it "im.tmp"
    enable write permissions for the file.

    i would strongly recommend using authentication if this is intended for a public site.


    most web host allow you to configure permissions, and that's the only setup you need to do.

    if this is on a winxp pro maching on your intranet, refer to http://support.microsoft.com/kb/271071 for more details.

  6. #6
    Join Date
    Oct 2008
    Posts
    16
    thnx

  7. #7
    Join Date
    Oct 2007
    Location
    Western Massachusetts, USA
    Posts
    387
    i made a really primative chat application with HTML frames and javascript, with a PHP text file write action with the text area frame reloading once a second
    Computer programmer / web developer.

  8. #8
    Join Date
    Oct 2008
    Posts
    16
    could u post it
    it would be very helpful

  9. #9
    Join Date
    Oct 2007
    Location
    Western Massachusetts, USA
    Posts
    387
    I do not have the code anymore, I did it in school (i go to a vocational/technical high school in the USA).

    However, it amounts to something like this:
    frame 1 takes 80&#37; of the page width, and has a javascript like this:
    Code:
    function refreshPage() {
    document.refresh();
    //the above may not work, try document.location = document.location; instead?
    }
    Frame 1 should have a PHP page that reads the file that Frame 2 writes to, and outputs all the text in it.
    Frame 1's PHP page should also have a form like this:
    <form method="get" action=".\frame1pagename.php"><input type="submit" value="Manual Refresh" /></form>

    Frame 2 has 20% of the page width and contains a form to submit to the same page the form is within, that form sends a username and a message to a PHP page which does this:
    Code:
    //check for file existing
    //if file exists, attempt to open
    //if open successful, write the validated user input (so no injection) to a new line with <br> at the end
    //recreate the form so user can submit another message
    //if open fails, report it to the user and do not recreate the <form>
    //if file is non-existant, report it to the user and do not recreate the <form>
    that is pretty much all there is to it, no need for fancy javascripts at all (except to refresh the page in frame 1, and in the event javascript fails, the button is there that uses standard HTML form to refresh it).

    I do not feel like writing all the code at this time. But I hope you can use this outline to help.

    Note that you can use the <noscript> element to surround the manual refresh button, so that in the event javascript is turned off or the broswer does not know what either tags are, it still has the form display.
    Last edited by savvykms; 11-08-2008 at 07:03 PM.
    Computer programmer / web developer.

  10. #10
    Join Date
    Oct 2008
    Posts
    16
    oh. do you know any sites that have just a basic chatroom

  11. #11
    Join Date
    Oct 2007
    Location
    Western Massachusetts, USA
    Posts
    387
    If you look at some alternatives to PHP etc, then you can use java applets to connect to an IRC network you can host with your website, or find an IRC network willing to let you host a chat room, there are plenty for this purpose. This is one of the most common methods of employing a chat room.


    IRC is Internet Relay Chat, it uses channels as chatrooms. Channel names begin with # or & usually, # should always work, & is for a chatroom visible only on 1 server, as IRC networks may have more than 1 server that you can connec to.

    You just go out, find a java applet such as DarkerIRC (google search jirc as well, if darker doesn't work right). and configure it to connect to an IRC network.

    Some popular networks are Freenode, QuakeNet, and UnderNet. I would suggest reading up on IRC and learning it, it is a great communication method. A lot of IRC networks allow you to register your nickname in the chatroom and server so no one else can use it, or they cannot at least register it themselves and not let you use it. The same tends to go for channels, so you have administrative access and people using your website don't complain of being kicked by some person who took over your channel.
    Computer programmer / web developer.

  12. #12
    Join Date
    Nov 2008
    Posts
    2

    Wink Hi

    Quote Originally Posted by ickla10 View Post
    Hi. I wanna make a javascript chatroom. it will have two frames. one will hold messages while the other will hold the message box. i will need scripts to make a text file on the fly on the server,update a message form to the text file and delete the file when done. if deleting is not possible the i just need the update the message to the text file or maybe html file for people 2 see. thanks
    Hi
    What's your name mines Georgia

  13. #13
    Join Date
    Nov 2008
    Posts
    2
    My names Georgia.I have a brother called josh.I have a step brother called Ben.I have a step sister called Shannon.Do you know any chat room's for any age.

Thread Information

Users Browsing this Thread

There are currently 2 users browsing this thread. (0 members and 2 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles