sample/ws-chat.html: allow to open it via file:// protocol

This commit is contained in:
Azat Khuzhin 2022-11-12 18:11:08 +01:00
parent 2dfad6c339
commit dda05f45e7

View File

@ -29,7 +29,11 @@ window.onload = function () {
};
if (window["WebSocket"]) {
conn = new WebSocket("ws://" + document.location.host + ":8080/ws");
var host = document.location.host;
if (!host) { /// file:///
host = "localhost";
}
conn = new WebSocket("ws://" + host + ":8080/ws");
conn.onclose = function (evt) {
var item = document.createElement("div");
item.innerHTML = "<b>Connection closed.</b>";