HTML and CSS Reference
In-Depth Information
.clientName
{
height: 20px;
width: 380px;
text-align: center;
font-size: 15px;
font-weight: bold;
}
</style>
3.
Now you'll add the JavaScript code that will make all of this work. Add the script
element shown in Listing 13-14 to the head element.
Listing 13-14. The JavaScript implementation
<script type="text/javascript">
var ws; // This is our socket
function connect() {
output("Connecting to host...");
try {
ws=new WebSocket("ws://localhost:8300/chat");
} catch (e) {
output(e);
}
ws.onopen=function () {
output("connected... ");
// Send the Agent sign-on message
var p=document.getElementById("agentName");
ws.send("[Agent SignOn:"+p.innerHTML+"]");
};
ws.onmessage=function (e) {
displayMsg(e.data);
};
ws.onclose=function () {
output("Connection closed");
};
};
// Send the input text to the server
function send(i) {
var input=document.getElementById("input"+i);
 
Search WWH ::




Custom Search