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">
<botton onclick="send()">送信</botton>
<ul id="sent"></ul>
<script>
const ws = new WebSocket("ws://localhost:8080");
ws.onMessage = (e) =>{
const li = document.createElement("li");
li.textContent = e.date;
document.getElementById("sent").appendChild(li);
};

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