-
Notifications
You must be signed in to change notification settings - Fork 1
/
9.html
48 lines (36 loc) · 947 Bytes
/
9.html
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
<!DOCTYPE html>
<html>
<head>
<title>9.html</title>
</head>
<body>
<h1>9.html</h1>
<p id="hello"> </p>
<input id="typeit"><input type ="button" id="sendit" value="Send Message">
<div id ="messages"></div>
<script src="/socket.io/socket.io.js"></script>
<script>
var socket =io.connect("/");
socket.on("connected", function(){
console.log("connected");
});
socket.on("disconnect", function(){
console.log("disconnected");
});
socket.on("hello",function(num){
document.getElementById("hello").innerHTML= "Hello World: "+num;
});
socket.on("messages", function(msg){
document.getElementById("messages").innerHTML += msg + "<br>";
});
document.getElementById("sendit").addEventListener("click",
function(evt){
var msg = document.getElementById("typeit").value;
if(msg){
socket.emit("typeit",msg);
document.getElementById("messages").innerHTML += msg + "<br>";
}
},false);
</script>
</body>
</html>