wenn's jemanden interessiert, bisher funktioniert schon folgendes:
chat.html:
[html]
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<title>Chattest</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link href="chat.css" rel="stylesheet" type="text/css" />
<script src="chat.js" type="text/javascript"></script>
</head>
<body>
<div class="chatwindow" id="chatwindow">
<div id="Output">
<p class="chatOutputLine">01: erste Zeile</p>
</div>
<form class="inputform" name="SendForm" action="" method="post" onsubmit="return AddMessage()">
<input type="text" id="inputLine" value="" size="30" />
<input type="submit" name="sendButton" value="Send" />
</form>
</div>
</body>
</html>
[/html]
chat.css:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
.chatwindow {
height: auto;
width: 300px;
border: 2px solid c
}
.chatOutputLine {
font-family: Arial, Helvetica, sans-serif;
font-style: normal;
background-color: #FFFF66;
letter-spacing: normal;
text-align: left;
word-spacing: normal;
white-space: normal;
margin: 1px;
border: 1px solid #0000FF;
}
.inputform {
background-color: c
border: 1px solid #FFFF66;
padding: 2px;
margin: 1px;
}
chat.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
function AddMessage () {
var inputLine = getInputLine();
var req = getXMLhttpRequestObject();
req.open("GET", "/cgi-bin/chat4.cgi?message=" + inputLine.value, null);
req.send(null);
parseMessageReply(req.responseText);
inputLine.value = ''; setInputFocus();
return false;
} // AddMessage
// --------------------------------------------------------
// private subs
// --------------------------------------------------------
function parseMessageReply (rText) {
var list = rText.split("\n");
for (var i=0; i<list.length; i++) {
if (list[i] != '') {
var line = list[i].split("\t");
writeLine(line[0] + ": " + line[1] + ': ' + line[2]);
}
}
} // parseMessageReply
// --------------------------------------------------------
function getInputLine () {
return ( document.getElementById('inputLine') );
// return (inputLine);
} // getInputLine
// --------------------------------------------------------
function setInputFocus () {
var inputLine = getInputLine(); inputLine.focus();
} // SetInputFocus
// --------------------------------------------------------
function writeLine (line, widget) {
// get output widget
widget = widget || 'Output';
var outputWidget = document.getElementById(widget);
// create a new p containing the text
var newLine = document.createElement("p");
var text = document.createTextNode(line);
// set class="chatOutputLine"
newLine.setAttribute("class", "chatOutputLine"); // for Firefox
newLine.setAttribute("className", "chatOutputLine"); // for IE
// and append it to the tree (=write)
newLine.appendChild(text);
outputWidget.appendChild(newLine);
} // writeLine
// --------------------------------------------------------
function getXMLhttpRequestObject () {
var ret
// for MS Internet explorer
var msxml = [
"Msxml2.XMLHTTP.5.0", "Msxml2.XMLHTTP.4.0", "Msxml2.XMLHTTP.3.0",
"Msxml2.XMLHTTP", "Microsoft.XMLHTTP" ];
if (window.ActiveXObject) {
for (var i=0; i<msxml.length; i++) {
try {
ret = new ActiveXObject(msxml[i]);
break;
} catch(e) {}
} // for
} // if
// for firefox and mozilla
ret = ret ? ret : new XMLHttpRequest();
return ret
} // getXMLhttpRequestObject
// --------------------------------------------------------
und cgi-bin/chat4.cgi
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#! /usr/bin/perl
use warnings;
use strict;
use POSIX;
use CGI ();
my $cgi = CGI->new();
print $cgi->header(-expires => "+1s");
my $nick = "Nickname";
print join("\t", &TS(), $nick, $cgi->param('message') ), "\n";
print join("\t", &TS(), $nick, $cgi->param('message') ), "\n";
# ------------------------------------------------------------
sub TS {
return POSIX::strftime("%H:%M:%S ", localtime(time));
} # GetTimeStamp
# ------------------------------------------------------------
mit sich selbst kann man schon wunderbar chatten