index.html 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Static File Index.HTML</title>
  5. <script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js"></script>
  6. </head>
  7. <body>
  8. <style>
  9. .chat__header {
  10. text-align: left;
  11. }
  12. .chat__message-content {
  13. border-radius: 5px;
  14. padding: 7px;
  15. background-color: #ccc;
  16. display: inline-block;
  17. margin-left: 5px;
  18. }
  19. </style>
  20. <body>
  21. <main class="main">
  22. <div class="chat">
  23. <h1 class="chat__header">Chat</h1>
  24. <div id="content" class = "chat__header">
  25. <div class="chat__item">
  26. <h1 id = "chat__message-content" class="chat__message-content"></h1>
  27. </div>
  28. <div class="send_form">
  29. Nick :<input type="text" id = 'nick' >
  30. Message :<input type="text" id = 'msg'>
  31. <button id="sendButton">Отправить</button>
  32. </div>
  33. </div>
  34. </main>
  35. <script>
  36. const socket = io('http://socketchat.ed.asmer.org.ua')
  37. socket.on('msg', msg => {
  38. console.log(msg)
  39. const my_P = document.createElement("div");
  40. my_P.innerHTML = '<b>' + msg.nick + ":" +"</b>" + msg.message
  41. document.getElementById("chat__message-content").appendChild(my_P)
  42. })
  43. sendButton.onclick = () => {
  44. console.log(nick.value , msg.value)
  45. socket.emit('msg', {nick: nick.value, message: msg.value})
  46. }
  47. </script>
  48. </body>
  49. </html>