Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

256
Vistas
Las funciones de Javascript no funcionan en la ventana de vista web

Soy nuevo en el enfoque de interfaz web. Por lo tanto, cuando necesite más información, por favor pregunte.

Tengo una aplicación con un backend go y un frontend html/css/js, que funciona bastante bien. Recientemente, intenté hacer la transición a webview , que también funcionó bien con respecto a la parte html y css. Sin embargo, mis funciones de javascript no funcionan y no sé cómo solucionar el problema.

Aquí hay un ejemplo mínimo e independiente que demuestra el problema. La ventana de vista web se abre y muestra el título y el botón. Sin embargo, hacer clic en el botón no abrirá el cuadro de diálogo de alerta.

Cualquier sugerencia que me indique en la dirección correcta es muy apreciada.

 package main import ( "github.com/webview/webview" "html/template" "net/http" ) type DummyData struct { PageTitle string } func main() { go start() w := webview.New(true) defer w.Destroy() w.SetTitle("Test webview") w.SetSize(800, 600, webview.HintNone) w.Navigate("http://localhost:80") w.Run() } func start() { tmpl, _ := template.New("lala").Parse("<!DOCTYPE html><body><h1>{{.PageTitle}}</h1><button onclick=\"myFunction()\">Try it</button><script>function myFunction() {alert(\"js working\");}</script></body>\n</html>") http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { data := DummyData{ PageTitle: "My webview page title", } tmpl.Execute(w, data) }) http.ListenAndServe(":80", nil) }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

En realidad, sus funciones JS funcionan, solo la alerta no. No estoy exactamente seguro de por qué, pero supongo que alertar, confirmar y avisar ya no recibirá mucho amor.

Esto aquí funciona:

 package main import ( "html/template" "net/http" "github.com/webview/webview" ) type DummyData struct { PageTitle string } func main() { go start() w := webview.New(true) defer w.Destroy() w.SetTitle("Test webview") w.SetSize(800, 600, webview.HintNone) w.Navigate("http://localhost:8000") w.Run() } func start() { const page = ` <!DOCTYPE html> <body> <h1> {{.PageTitle}} </h1> <button onclick="myFunction()">Try it</button> <div id="d1" hidden> poor man's alert </div> <script> function myFunction() { d1.hidden = !d1.hidden // alert("js working"); } </script> </body> </html> ` tmpl, _ := template.New("lala").Parse(page) http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { data := DummyData{ PageTitle: "My webview page title", } tmpl.Execute(w, data) }) http.ListenAndServe(":8000", nil) }
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda