forked from rauchg/chat-example
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
32 lines (32 loc) · 885 Bytes
/
index.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
<!doctype html>
<html>
<head>
<title>wwlib chat</title>
<link rel="stylesheet" type="text/css" href="css/main.css">
</head>
<body>
<ul id="messages"></ul>
<form action="">
<input id="m" autocomplete="off" /><button>Send</button>
</form>
<script src="https://cdn.socket.io/socket.io-1.2.0.js"></script>
<script src="http://code.jquery.com/jquery-1.11.1.js"></script>
<script>
var socket = io();
var msgCount = 0;
$('form').submit(function(){
socket.emit('chat message', $('#m').val());
$('#m').val('');
return false;
});
socket.on('chat message', function(msg){
msgCount++;
if (msgCount > 5) {
$('#messages').empty();
msgCount = 0;
}
$('#messages').append($('<li>').text(msg));
});
</script>
</body>
</html>