diff --git a/examples/chat/home.html b/examples/chat/home.html index 7262918..a39a0c2 100644 --- a/examples/chat/home.html +++ b/examples/chat/home.html @@ -9,7 +9,7 @@ window.onload = function () { var log = document.getElementById("log"); function appendLog(item) { - var doScroll = log.scrollTop === log.scrollHeight - log.clientHeight; + var doScroll = log.scrollTop > log.scrollHeight - log.clientHeight - 1; log.appendChild(item); if (doScroll) { log.scrollTop = log.scrollHeight - log.clientHeight; @@ -29,7 +29,7 @@ window.onload = function () { }; if (window["WebSocket"]) { - conn = new WebSocket("ws://{{$}}/ws"); + conn = new WebSocket("ws://" + document.location.host + "/ws"); conn.onclose = function (evt) { var item = document.createElement("div"); item.innerHTML = "Connection closed."; diff --git a/examples/chat/main.go b/examples/chat/main.go index d08f895..74615d5 100644 --- a/examples/chat/main.go +++ b/examples/chat/main.go @@ -6,13 +6,11 @@ package main import ( "flag" - "html/template" "log" "net/http" ) var addr = flag.String("addr", ":8080", "http service address") -var homeTemplate = template.Must(template.ParseFiles("home.html")) func serveHome(w http.ResponseWriter, r *http.Request) { log.Println(r.URL) @@ -24,8 +22,7 @@ func serveHome(w http.ResponseWriter, r *http.Request) { http.Error(w, "Method not allowed", 405) return } - w.Header().Set("Content-Type", "text/html; charset=utf-8") - homeTemplate.Execute(w, r.Host) + http.ServeFile(w, r, "home.html") } func main() { diff --git a/examples/command/home.html b/examples/command/home.html index 72fd02b..19c4612 100644 --- a/examples/command/home.html +++ b/examples/command/home.html @@ -2,47 +2,53 @@