Skip to content

Instantly share code, notes, and snippets.

@anantn
Created May 6, 2013 18:13
Show Gist options
  • Select an option

  • Save anantn/5526948 to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown

thanks u

@teknodeno
Copy link
Copy Markdown

İts very good but you can add username

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