forked from a-mean-blogger/node-js-socket-io-chatting-site
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.html
More file actions
42 lines (42 loc) · 1.2 KB
/
client.html
File metadata and controls
42 lines (42 loc) · 1.2 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Chat</title>
<style>
.chat_log{ width: 95%; height: 200px; }
.name{ width: 10%; }
.message{ width: 70%; }
.chat{ width: 10%; }
</style>
</head>
<body>
<div>
<textarea id="chatLog" class="chat_log" readonly></textarea>
</div>
<form id="chat">
<input id="name" class="name" type="text" readonly>
<input id="message" class="message" type="text">
<input type="submit" class="chat" value="chat"/>
</form>
<div id="box" class="box">
<script src="/socket.io/socket.io.js"></script>
<script src="//code.jquery.com/jquery-1.11.1.js"></script>
<script>
var socket = io();
$('#chat').on('submit', function(e){
socket.emit('send message', $('#name').val(), $('#message').val());
$('#message').val("");
$("#message").focus();
e.preventDefault();
});
socket.on('receive message', function(msg){
$('#chatLog').append(msg+'\n');
$('#chatLog').scrollTop($('#chatLog')[0].scrollHeight);
});
socket.on('change name', function(name){
$('#name').val(name);
});
</script>
</body>
</html>