// 例 function intro() { var team = document.getElementById("word"), button = document.getElementById("push"), info = document.getElementById("info"); var conn, PORT=8888, server = location.hostname||"localhost"; alert(server); function initConn() { try { conn = new WebSocket('ws://' + server + ':' + PORT + '/'); conn.onopen = function() {}; // Nothing special conn.onerror = function(err) { alert('WebSocket failure: ' + err) }; conn.onmessage = function(ev) { info.textContent = ev.data; }; conn.onclose = function(ev) { info.textContent = "接続断: 頃合を見てPUSHを押してください。"; conn = null; }; info.textContent = "..."; } catch (err) { alert("Socket Creation Error\n\ Firefoxですか? URLウィンドウに about:config と入れて\n\ Search: 窓に websocket と入れて、\n\ network..websocket.allowInsecureFromHTTP\n\ の行をダブルクリックして true に変えてください。\n" + err); } } function push(ev) { if (!conn) initConn(); conn.send(team.value); } button.addEventListener("mousedown", push, false); initConn(); } document.addEventListener("DOMContentLoaded", intro, false);