Browse Source

class work

Gennadysht 2 years ago
parent
commit
15ff2eb345
2 changed files with 40 additions and 1 deletions
  1. 1 1
      js/09/hw09_08countries and cities.html
  2. 39 0
      msg.html

+ 1 - 1
js/09/hw09_08countries and cities.html

@@ -29,4 +29,4 @@
             });
  
     </script>
-</body>
+</body>+

+ 39 - 0
msg.html

@@ -0,0 +1,39 @@
+<!DOCTYPE HTML>
+<html>
+
+<head>
+    <h1>message chat</h1>
+    <title>
+        Static File Index.HTML
+    </title>
+    <script src='https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js'></script>
+</head>
+
+<body>
+
+    <div id='formContainer'> </div>
+    <input type="text" id="nick" name="name" /><br>
+    <input type="text" id="msg" name="name" /><br>
+    <button type="button" id="btn"> SEND</button>
+    <script>
+        const socket = io("http://socketchat.ed.asmer.org.ua");
+        socket.on('msg', (msg) => {
+            console.log(msg);
+            // document.createElement
+            const div = document.createElement('div')
+            div.innerHTML = `<strong> ${msg.nick}</strong>: ${msg.message}`
+            formContainer.append(div);
+
+        });
+        document.getElementById('btn').onclick = () => {
+            console.log(
+                `${document.getElementById('nick').value}:  ${document.getElementById('msg').value}`
+            );
+            socket.emit('msg', { nick: nick.value, message: msg.value });
+        };
+    </script>
+
+
+</body>
+
+</html>