Golang text/template.JSEscape() function example
package text/template
Golang text/template.JSEscape() function usage example
package main
import (
"bytes"
"fmt"
"text/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
+15.6k Golang : ROT47 (Caesar cipher by 47 characters) example
+14.9k Golang : Basic authentication with .htpasswd file
+13.7k Golang : Image to ASCII art example
+9k Golang : automatically figure out array length(size) with three dots
+7.2k Ubuntu : connect() to unix:/var/run/php5-fpm.sock failed (13: Permission denied) while connecting to upstream
+5.4k Javascript : How to loop over and parse JSON data?
+36.5k Golang : Save image to PNG, JPEG or GIF format.
+8.7k Golang : How to join strings?
+12.2k Golang : Simple client-server HMAC authentication without SSL example
+20.4k nginx: [emerg] unknown directive "passenger_enabled"
+4.1k Javascript : Empty an array example
+8.1k Golang : Variadic function arguments sanity check example