Shardik wrote:Linux 19.3 'Tricia' x64: the contents of the root directory are displayed in the WebGadget; the debug message "Button was clicked!" is not displayed!
Before I posted my above code here, I tested it on Linux and Windows XP.
Under Linux additional code was needed for the WebGadget because JavaScript is not enabled by default and SetGadgetItemText() is not supported. I omitted this additional code here because I assumed that only a macOS solution is requested and not a cross-platform solution.
Here the above code with the additional code for Linux:
Code: Select all
ImportC "-lwebkitgtk-3.0"
webkit_web_settings_new()
webkit_web_view_set_settings(*webkitWebView, *webkitSettings)
webkit_web_view_load_string(*webView, content.p-utf8, *mimeType, *encoding, *baseURI)
EndImport
OpenWindow(0, 0, 0, 600, 300, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
WebGadget(0, 10, 10, 580, 240, "")
; Enable Javascript
*webKitSettings = webkit_web_settings_new()
webkit_web_view_set_settings(GadgetID(webGadget), *webkitSettings)
; Set HTML code
webkit_web_view_load_string(GadgetID(0), ~"<html><body>Hello <form><button onclick='document.body.innerText=1234; window.location.href = \"#click\"; return false'>Test</button></form></body></html>", 0, 0, 0)
Repeat
EventID = WaitWindowEvent()
If url$ <> GetGadgetText(0)
url$ = GetGadgetText(0)
If StringField(url$, 2, "#") = "click"
Debug "Button was clicked!"
EndIf
EndIf
Until EventID = #PB_Event_CloseWindow
Shardik wrote:MacOS 10.14.6 'Mojave': the debug message "Button was clicked!" is not displayed!
Pity. I just saw in the PB help that SetGadgetItemText() is also not supported on macOS.
And if you use this instead of SetGadgetItemText():
Code: Select all
Procedure SetHTMLCode(webGadget, htmlCode$)
Protected filePath$ = GetTemporaryDirectory() + "temp.html"
Protected file = CreateFile(#PB_Any, filePath$)
If file
WriteString(file, htmlCode$)
CloseFile(file)
SetGadgetText(webGadget, "file:///" + filePath$)
EndIf
EndProcedure
SetHTMLCode(0, ~"<html><body>Hello <form><button onclick='document.body.innerText=1234; window.location.href = \"#click\"; return false'>Test</button></form></body></html>")