index.html 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>
  5. Static File Index.HTML
  6. </title>
  7. <script src='https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js'></script>
  8. </head>
  9. <body>
  10. <div id='formContainer'>
  11. <p><input id='nickId' style="font-weight: 600"> Your nick </p>
  12. <p><input id='messageId' style="height: 100px"> Your message</p>
  13. <p><button id='sendBtn' onclick="sendBtnFnc()">Send</button></p>
  14. <section id='outputSection'></section>
  15. </div>
  16. <script>
  17. const socket = io()
  18. </script>
  19. <script>
  20. socket.on('msg', msg => outputSection.insertAdjacentHTML('afterbegin',`<div style='margin-top:10px; border: 2px solid purple; border-radius:3px; width:300px; padding:px'>${msg.nick}: ${msg.message}</div>`))</script>
  21. <script>
  22. const sendBtnFnc = () => {
  23. socket.emit('msg', { nick: String(nickId.value), message: String(messageId.value) })
  24. messageId.value='';
  25. }
  26. </script>
  27. </body>
  28. </html>