HTML code streamed into WebGadget cannot run external JavaScript
Posted: Mon Apr 22, 2024 9:49 pm
It seems that external JavaScript cannot be executed from code that is streamed into the webgadget.
Example with external JavaScript in separate file (does not work):
myScript.js (located in the same directory as the .pb file):
It works, if the JavaScript is directly embedded in the html code
Example with embedded JavaScript (does work):
It does also work if the test.html file is set as URL:
Thank you very much & Regards
Example with external JavaScript in separate file (does not work):
Code: Select all
If OpenWindow(0, 0, 0, 600, 300, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
WebGadget(0, 0, 0, 600, 300, "", #PB_Web_Edge)
html$="<button id=''demo'' type=''button'' onclick=''myFunction()''>Click Me</button><script src=''file:///"+GetCurrentDirectory()+"myScript.js''></script>"
html$=ReplaceString(html$,"''",Chr(34))
Debug html$
SetGadgetItemText(0, #PB_Web_HtmlCode, html$)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Code: Select all
function myFunction() {
document.getElementById("demo").innerHTML = "Clicked";
}
Example with embedded JavaScript (does work):
Code: Select all
If OpenWindow(0, 0, 0, 600, 300, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
WebGadget(0, 0, 0, 600, 300, "", #PB_Web_Edge)
html$="<button id=''demo'' type=''button'' onclick=''myFunction()''>Click Me</button><script>function myFunction(){document.getElementById(''demo'').innerHTML = ''Clicked'';}</script>"
html$=ReplaceString(html$,"''",Chr(34))
Debug html$
SetGadgetItemText(0, #PB_Web_HtmlCode, html$)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Code: Select all
If OpenWindow(0, 0, 0, 600, 300, "WebGadget", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
WebGadget(0, 0, 0, 600, 300, "file:///"+GetCurrentDirectory()+"test.html", #PB_Web_Edge)
Repeat
Until WaitWindowEvent() = #PB_Event_CloseWindow
EndIf
Thank you very much & Regards