-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathchatroom.html
86 lines (78 loc) · 1.99 KB
/
chatroom.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<!doctype html>
<head>
<title>Instant Message Chat</title>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- bootstrap CDN -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
<style>
header {
padding: 20px;
background-color: rgb(255,255,255, 1);
}
body {
background-image: url(../img/question_bg.jpg);
background-repeat: no-repeat;
background-size: 100% ;
}
ul {
color: #DCDCDC;
height: 100%;
list-style: none;
word-wrap: break-word;
}
div.row {
position: absolute;
width: 100%;
bottom: 10px;
}
input {
width:100%;
height:38px;
border-radius: 12px;
padding: 5px;
}
button {
background-color: #008CBA;
width:100%;
height:38px;
min-width: 60px;
border: solid 1px #008CBA;
border-radius: 12px;
}
</style>
</head>
<body>
<header class="text-center">
<img src="img/chat_icon.png" style="height: 20px; width: 20px;">
Chat
</header>
<div class="container-fluid">
<ul id="messages"></ul>
<form action="">
<div class="row">
<div class="col-10"><input id="m" autocomplete="off" /></div>
<div class="col-2"><button>Send</button></div>
</div>
</form>
</div>
<!-- script -->
<script src="/socket.io/socket.io.js"></script>
<script src="https://code.jquery.com/jquery-1.11.1.js"></script>
<script>
// Prompt for setting a username
var username = prompt("Please enter your name", "Harry Potter");
$(function () {
var socket = io();
$('form').submit(function(){
socket.emit('chat message', username + " : " +$('#m').val());
return false;
});
socket.on('chat message', function(msg){
$('#messages').append($('<li>').text(msg));
});
});
</script>
</body>
</html>