Perhaps you have not taken into account that jQuery needs a little time before it is ready for use?
Code: Select all
Enumeration
#Window
#WebViewGadget
#Button
EndEnumeration
Procedure ButtonGadgetEvent()
WebViewExecuteScript(#WebViewGadget, "$('#testDiv').addClass('blueBackground')")
EndProcedure
HTML.s = ~"<!DOCTYPE html>\n" +
~"<html lang='en'>\n" +
~" <head>\n" +
~" <meta charset='utf-8'/>\n" +
~"" +
~" <style>\n" +
~" .blueBackground { background-color: blue }\n" +
~" </style>\n" +
~"" +
~" <script type='text/javascript' src='https://code.jquery.com/jquery-3.7.1.min.js'></script>\n" +
~"" +
~" <script type='text/javascript'>\n" +
~" $(document).ready(function() {\n" +
~" alert('jQuery is ready!');\n" +
~" });\n" +
~" </script>\n" +
~" </head>\n" +
~" <body>\n" +
~" <div id='testDiv' style='width: 100px; height: 100px; border: 1px solid black'></div>\n" +
~" </body>\n" +
~"</html>";
OpenWindow(#Window, 0, 0, 1000, 800, "Hello", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
ButtonGadget(#Button, 0, 0, 100, 30, "AddClass")
WebViewGadget(#WebViewGadget, 0, 30, 1000, 800 - 30, #PB_WebView_Debug)
SetGadgetItemText(#WebViewGadget, #PB_WebView_HtmlCode, HTML)
BindGadgetEvent(#Button, @ButtonGadgetEvent())
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
Hint: If you create the WebView gadget with the #PB_WebView_Debug flag, you can open the developer console by right-clicking on the gadget in the pop-up menu.