PowerBuilder - Load html as string example
The load html as string demo as the following code in the open event:
event open;// create the WebView2 control on opening
edgewebbrowser.object.CreateWebView()
infotext.text = "~r~nLoads the displayed data from a string, the context menu and developers mode have been disabled."
// example on how you can unlock the control once you acquired a license.
edgewebbrowser.Object.UnlockControl("ExampleCompany", "WI5PO2-2KSU3Q-HWFXFU-IUMU2V-QF8P2F")
end event
This creates the WebView2 control via CreateWebView, then it sets the text of the "tooltip" control at the bottom of the screen and it's followed by an example of how you can register the control if you have bought a license.
Once the WebView2 control is loaded, it will trigger the OnCreateWebViewCompleted event and that's where we handle the rest.
event oncreatewebviewcompleted(long hresult);string ls_FilePath
// disable right click menu
object.DefaultContextMenusEnabled = False
// No F12 either
object.DevToolsEnabled = False
string ls_Path
string ls_HtmlFile
ls_Path = strGetPowerBuilderDemoPath()
ls_HtmlFile = ls_Path + "\html\flipCard3D.html"
// Make sure the source exists so that we fail gracefully if it cannot be found.
if not FileExists(ls_HtmlFile) then
MessageBox("Test", "Internal Error: HTML file " + ls_HtmlFile + " does not exist.")
return
end if
// Read the html from the file into a string
integer li_FileNum
string ls_Html
long ll_FLength
ll_FLength = FileLength64(ls_HtmlFile)
li_FileNum = FileOpen(ls_HtmlFile, &
TextMode!)
IF ll_FLength < 32767 THEN
FileReadEx(li_FileNum, ls_Html)
END IF
object.NavigateToString(ls_Html)
end event
We disable the right click menu (DefaultContextMenuEnabled) and turn off the developer tools (DevToolsEnabled) so that the user can no longer "peek behind the scenes".
Next up we locate the html file we want to load.
Read that file into a string ls_html and once that is done, we display the html via NavigateToString.
AntView - The MS Edge WebView2 ActiveX control Date last changed: 09/30/2024