Skip to content

Instantly share code, notes, and snippets.

@anantn
Created May 6, 2013 18:13
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save anantn/5526948 to your computer and use it in GitHub Desktop.
Save anantn/5526948 to your computer and use it in GitHub Desktop.
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>
@caracoline
Copy link

thanks u

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment