7 Einträge, 1 Seite |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
var messageId = 1;
function AddMessage () {
var inputLine = document.getElementById('inputLine');
var output = document.getElementById('Output');
var newLine = document.createElement("p");
newLine.setAttribute("class","chatOutputLine");
var text = document.createTextNode(messageId + ": " + inputLine.value);
output.appendChild( newLine.appendChild(text) );
alert('Printed: ' + inputLine.value);
inputLine.focus();
inputLine.value = '';
messageId++;
return false;
} // AddMessage
1: dfgh2: dfh3: zeile 34: vierte zeile5: fuenfte zeile
1
2
3
4
5
6
7
8
9
10
11
.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: medium solid #0000FF;
}
output.appendChild( newLine.appendChild(text) );
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
var messageId = 1;
function AddMessage () {
var inputLine = document.getElementById('inputLine');
var output = document.getElementById('Output');
var newLine = document.createElement("p");
var text = document.createTextNode(messageId + ": " + inputLine.value);
newLine.setAttribute("class", "chatOutputLine"); // for Firefox
newLine.setAttribute("className", "chatOutputLine"); // for IE
newLine.appendChild(text);
output.appendChild(newLine);
alert('Printed: ' + inputLine.value);
inputLine.focus();
inputLine.value = '';
messageId++;
return false;
} // AddMessage
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;
}
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
// --------------------------------------------------------
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
# ------------------------------------------------------------
(receiveReq.readyState == 4 || receiveReq.readyState == 0)
1
2
3
4
5
6
7
req.onreadystatechange = function () {
if (req.readyState == 4) {
if (req.status == 200) {
parseMessageReply(req.responseText);
}
}
}
7 Einträge, 1 Seite |