HTML and CSS Reference
In-Depth Information
try {
ws.send(i+":"+input.value);
var o=document.getElementById("chat"+i);
o.innerHTML=o.innerHTML+"<p><b>Me:</b>"+input.value+"</p>";
input.value="";
} catch (e) {
output(e);
}
}
// Add text to the debug area
function output(msg) {
var o=document.getElementById("output");
o.innerHTML=o.innerHTML+"<p>"+msg+"</p>";
};
// Handle a received message
function displayMsg(msg) {
var i=msg.substring(0, 1);
var cmd=msg.substring(0, 12);
// For the initial message from the server, save the client's name
if (cmd === "[ClientName:") {
displayClientName(msg.substring(12));
}
// If the client has disconnected, clear the chat window
else if (cmd === "[ClientClose") {
resetClient(msg.substring(13,14));
}
// Display the message in the debug area is not formatted properly
else if (i !="1" && i !="2" && i !="3" && i !="4") {
output(msg)
}
// Display the message in the chat window
else {
var o=document.getElementById("chat"+i);
o.innerHTML=o.innerHTML+"<p><b>Client:</b>" +
msg.substring(3, msg.length)+"</p>";
}
};
// Display the client's name in the chat window
function displayClientName(msg) {
var i=msg.substring(0, 1);
var o=document.getElementById("client"+i);
o.innerHTML=msg.substring(1, msg.length - 1);
}
Search WWH ::




Custom Search