-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex
More file actions
46 lines (38 loc) · 1.22 KB
/
index
File metadata and controls
46 lines (38 loc) · 1.22 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
43
44
45
46
<!DOCTYPE html>
<html lang="en">
<head>
<title>"Connecting Hearts, one Chat at a time."
</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel = "stylesheet" href="style.css">
<script>
var name = prompt("Please enter your name");
</script>
</head>
<body>
<div id="intro">
<h1>ChatRoom</h1>
</div>
<ul id="messages"></ul>
<form action="">
<input id="m" placeholder="Enter your message..." autocomplete="off" required /><button>Send</button>
</form>
<script src="/socket.io/socket.io.js"></script>
<script src="https://code.jquery.com/jquery-3.4.1.min.js"></script>
<script>
var socket = io();
socket.emit('joining msg', name);
$('form').submit(function(e) {
e.preventDefault(); // will prevent page reloading
socket.emit('chat message', (name + ': ' + $('#m').val()));
$('#messages').append($('<li id="list">').text('You: ' + $('#m').val()));
$('#m').val('');
return false;
});
socket.on('chat message', function(msg){
$('#messages').append($('<li>').text(msg));
});
</script>
</body>
</html>