Created
May 6, 2013 18:13
-
-
Save anantn/5526948 to your computer and use it in GitHub Desktop.
A simple, plugin-free chat room - build with Firebase
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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?