diff --git a/example_programs/websocket_example/static/index.html b/example_programs/websocket_example/static/index.html index 86128e10..23355cfd 100644 --- a/example_programs/websocket_example/static/index.html +++ b/example_programs/websocket_example/static/index.html @@ -22,6 +22,15 @@ var mySocket = false; var curFile = false; + function escapeMessage(htmlStr) { + return htmlStr.replace(/&/g, "&") + .replace(//g, ">") + .replace(/"/g, """) + .replace(/'/g, "'"); + + } + function connectSocket(echo) { if (location.protocol === "https:") { mySocket = new WebSocket("wss://" + location.hostname + ":" + location.port + "/websocket" + (echo?"/echo":"")); @@ -32,7 +41,7 @@ if (event.data instanceof Blob) { var message = "
Binary message received: " + event.data.size + " bytes
Text message received: " + event.data + "
Text message received: " + escapeMessage(event.data) + "
Message sent: " + $("#sendMessage").val() + "
Message sent: " + escapeMessage($("#sendMessage").val()) + "