Golang html/template.JSEscape function example
package html/template
JSEscape writes to w(1st parameter) the escaped JavaScript equivalent of the plain text data b (2nd parameter).
Golang html/template.JSEscape function usage example
package main
import (
"bytes"
"fmt"
"html/template"
)
func main() {
w := bytes.NewBufferString("")
b := []byte("<script>document.getElementById('demo').innerHTML = cars;</script>")
template.JSEscape(w, b)
fmt.Println(w)
}
Output :
\x3Cscript\x3Edocument.getElementById(\'demo\').innerHTML = cars;\x3C/script\x3E
Reference :
Advertisement
Something interesting
Tutorials
+12.6k Golang : Drop cookie to visitor's browser and http.SetCookie() example
+6.6k Golang : Totalize or add-up an array or slice example
+17.7k How to enable MariaDB/MySQL logs ?
+7.1k Javascript : How to get JSON data from another website with JQuery or Ajax ?
+4.5k Java : Generate multiplication table example
+9.6k Golang : Validate IPv6 example
+5.9k Golang : Use NLP to get sentences for each paragraph example
+24.5k Golang : Change file read or write permission example
+40.5k Golang : Convert to io.ReadSeeker type
+13.5k Golang : Read XML elements data with xml.CharData example