Compare commits
2 Commits
| Author | SHA1 | Date |
|---|---|---|
|
|
c3a4e73f28 | 4 weeks ago |
|
|
e52307ee4d | 4 weeks ago |
@ -0,0 +1,3 @@
|
||||
node_modules/
|
||||
package-lock.json
|
||||
*.*.swp
|
||||
@ -1,9 +1,40 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Socket.io Chat</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1> Hello Marx from index.html file </h1>
|
||||
<p>This is some text</p>
|
||||
<h1> My Chat App</h1>
|
||||
<ul id='messages'></ul>
|
||||
|
||||
<form id='form'>
|
||||
<input id='input' autocomplete='off'/> <button type='submit'>Send</button>
|
||||
</form>
|
||||
|
||||
<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 messages
|
||||
form.addEventListener('submit', function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
if (input.value) {
|
||||
socket.emit('chat message', input.value);
|
||||
input.value = '';
|
||||
}
|
||||
});
|
||||
|
||||
// Receive messages
|
||||
socket.on('chat message', function(msg) {
|
||||
const item = document.createElement('li');
|
||||
item.textContent = msg;
|
||||
messages.appendChild(item);
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
|
||||
Loading…
Reference in New Issue