A simple, plugin-free chat room - build with Firebase
<html> | |
<head> | |
<script src="https://cdn.firebase.com/v0/firebase.js"></script> | |
</head> | |
<body> | |
<ul id="chat-list"> | |
</ul> | |
<input type="text" id="msg"/> | |
<input type="button" id="send" value="Send"/> | |
<script> | |
var ref = new Firebase("https://anant.firebaseio.com/chat").limit(5); | |
ref.on("child_added", function(snap) { | |
var chatItem = document.createElement("li"); | |
chatItem.innerHTML = JSON.stringify(snap.val()); | |
chatItem.id = snap.name(); | |
document.getElementById("chat-list").appendChild(chatItem); | |
}); | |
ref.on("child_removed", function(snap) { | |
var item = document.getElementById(snap.name()); | |
item.parentNode.removeChild(item); | |
}); | |
document.getElementById("send").onclick = function() { | |
console.log("test"); | |
var msg = document.getElementById("msg").value; | |
ref.ref().push(msg); | |
}; | |
</script> | |
</body> | |
</html> |
This comment has been minimized.
This comment has been minimized.
caracoline
commented
Jan 25, 2018
thanks u |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
garbearlez commentedNov 20, 2017
is there a way to make a login for this, so that if you have more than 3 people, you can tell who it is?