Skip to content

Instantly share code, notes, and snippets.

@stevenchan
Created January 22, 2010 08:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevenchan/283628 to your computer and use it in GitHub Desktop.
Save stevenchan/283628 to your computer and use it in GitHub Desktop.
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="form.js"></script>
<script type="text/javascript">
function receiveMessage(event){
if(event.origin !== "http://127.0.0.1:8000"){ return; }
if(event.data === "connected"){ return; }
if(event.data === "disconnected"){ return; }
$("#msg_textarea").get(0).value += event.data + "\n";
//scroll to the bottom
$("#msg_textarea").scrollTop(999999);
}
$(document).ready(function(){
window.addEventListener("message", receiveMessage, false);
$("#msg_form").ajaxForm(function(){
//clear the message input field after sending a message
$("#msg_form input[name='message']").attr("value", "");
//focus to the message input field again
$("#msg_form input[name='message']").focus();
});
});
</script>
<title>Chatroom</title>
</head>
<body>
<textarea id="msg_textarea"
rows="10"
cols="10"
readonly="readyonly"
style="width:500px;height:400px;"></textarea>
<form id="msg_form" method="post" action="send.php">
<input type="text" name="message" style="width:500px"/>
</form>
<iframe style="position:absolute;top:-500px;left:-500px;" src="http://127.0.0.1:8000/iframe?channel=chat"></iframe>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment