Newer
Older
kensho2 / ws.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>---</title>
<link rel="stylesheet" type="text/css" >
<script type="text/javascript"></script>
</head>
<body>
<input id="word">
<button onclick="send()">送信</button>
<ul id="sent"></ul>
<script>
const ws = new WebSocket("ws://localhost:8080");
ws.onmessage = (e) =>{
const li = document.createElement("li");
li.textContent = e.data;
document.getElementById("sent").appendChild(li);
};

function send(){
	const abc = document.getElementById("word");
	ws.send(abc.value);
	abc.value = "";
}
</script>
</body>
</html>