Compare commits
2 Commits
2b4072a6b7
...
2b49232e6d
| Author | SHA1 | Date |
|---|---|---|
|
|
2b49232e6d | 4 weeks ago |
|
|
5b623c8a9c | 4 weeks ago |
@ -1,8 +1,40 @@
|
|||||||
|
<!DOCTYPE HTML>
|
||||||
<html>
|
<html>
|
||||||
|
<head>
|
||||||
|
<title>Chat App</title>
|
||||||
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1> Hello Angelus from index.html file </h1>
|
<h1> A new Chat App </h1>
|
||||||
|
|
||||||
|
<ul id='messages'></ul>
|
||||||
|
<form id='form'>
|
||||||
|
<input id='input'autocomplete='off'/><button type='submit'>Send</button>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
|
||||||
<p>This is some text </p>
|
<p>This is some text </p>
|
||||||
<script src='/socket.io/socket.io.js'></script>
|
<script src='/socket.io/socket.io.js'></script>
|
||||||
<script>var socket = io();</script>
|
<script>
|
||||||
|
const socket = io();
|
||||||
|
const form = document.getElementById('form');
|
||||||
|
const input = document.getElementById('input');
|
||||||
|
const messages = document.getElementById('messages');
|
||||||
|
|
||||||
|
// send message
|
||||||
|
form.addEventListener('submit', function(e) {
|
||||||
|
e.preventDefault();
|
||||||
|
if(input.value) {
|
||||||
|
socket.emit('chat message',input.value);
|
||||||
|
input.value = '';
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
//receive message
|
||||||
|
socket.on('chat message', function(msg){
|
||||||
|
const item = document.createElement('li');
|
||||||
|
item.textContent = msg;
|
||||||
|
messages.appendChild(item);
|
||||||
|
});
|
||||||
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Loading…
Reference in New Issue