Skip to content

Instantly share code, notes, and snippets.

@anantn
Created May 6, 2013 18:13
Show Gist options
  • 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>
@garbearlez
Copy link

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?

@caracoline
Copy link

thanks u

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