Webview callback with umlaut

Just starting out? Need help? Post your questions and find answers here.
Sirius-2337
User
User
Posts: 59
Joined: Sat May 14, 2011 10:39 am

Webview callback with umlaut

Post by Sirius-2337 »

Hi,
BindWebviewCallback does not not work when the returned string contains umlauts.
But no error messages in PB or WebView console.
Example Code:

Code: Select all

Procedure ComputeJS(JsonParameters$)
;   Protected string$ = ~"{ \"text\": \"ABC\"}"
  Protected string$ = ~"{ \"text\": \"äöüÄÖÜß^âá\"}"
;   Protected string$ = ~"{ \"text\": \""+EscapeString("ABC", #PB_String_EscapeJSON)+~"\"}"
;   Protected string$ = ~"{ \"text\": \""+EscapeString("äöüÄÖÜß^âá", #PB_String_EscapeJSON)+~"\"}"
  Debug "compute"
  ProcedureReturn UTF8(string$)
EndProcedure

OpenWindow(0, 100, 100, 400, 400, "Hello", #PB_Window_SystemMenu)

WebViewGadget(0, 0, 0, 400, 400, #PB_WebView_Debug)

SetGadgetItemText(0, #PB_WebView_HtmlCode, 
                  ~"<button id=\"compute\">Compute</button>\n"+
                  ~"<div>Result of computation: <span id=\"compute-result\">0</span></div>\n"+
                  ~"<script charset='utf-8'>\n"+
                  ~"  const [computeElement, computeResultElement] =\n"+
                  ~"    document.querySelectorAll(\"#compute, #compute-result\");\n"+
                  ~"  document.addEventListener(\"DOMContentLoaded\", () => {\n"+
                  ~"    computeElement.addEventListener(\"click\", () => {\n"+
                  ~"      computeElement.disabled = true;\n"+
                  ~"      window.compute(6, 7).then(result => {\n"+
                  ~"        console.log('result: ', result.text);"+
                  ~"        computeResultElement.textContent = result.text;\n"+
                  ~"        computeElement.disabled = false;\n"+
                  ~"      });\n"+
                  ~"    });\n"+
                  ~"  });\n"+
                  ~"</script>")
  
BindWebViewCallback(0, "compute", @ComputeJS())

WebViewExecuteScript(0, "document.getElementById('compute').textContent = 'äöüÄÖÜß^âá';")

Repeat 
  Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
Am i doing something wrong, or is this a bug?

(WebViewExecuteScript works fine with umlauts btw)

Tested with PB 6.12 Beta4 x64 on Windows10 x64
infratec
Always Here
Always Here
Posts: 7662
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Webview callback with umlaut

Post by infratec »

Hm ...

small letters are working:

Code: Select all

Protected string$ = ~"{ \"text\": \"äöü^âá\"}"
Sirius-2337
User
User
Posts: 59
Joined: Sat May 14, 2011 10:39 am

Re: Webview callback with umlaut

Post by Sirius-2337 »

infratec wrote: Fri Sep 06, 2024 10:23 pm Hm ...

small letters are working:

Code: Select all

Protected string$ = ~"{ \"text\": \"äöü^âá\"}"
Oh, you're right didn't notice that.
Some more characters that do not work:

Code: Select all

~"{ \"text\": \"Þ\"}"
~"{ \"text\": \"Ø\"}"
~"{ \"text\": \"×\"}"
Post Reply