1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
<!DOCTYPE html>
<html>
<head>
<script src="jquery.min.js"></script>
<script>
window.onload = function() {
var data = {};
var s = new WebSocket("ws://127.0.0.1:%(port)s/chat");
s.onopen = function() {
s.send('New participant joined');
};
s.onmessage = function(e) {
$("#chat").append("<div>" + e.data + "</div>");
};
$('#chatform').submit(function (evt) {
var line = $('#chatform [type=text]').val()
$('#chatform [type=text]').val('')
s.send(line);
return false;
});
};
</script>
</head>
<body>
<h3>Chat!</h3>
<p>(Only tested in Chrome)</p>
<div id="chat" style="width: 60em; height: 20em; overflow:auto; border: 1px solid black">
</div>
<form id="chatform">
<input type="text" />
<input type="submit" />
</form>
</body>
</html>
|