Syntax
Success = WebViewNavigate(WebView, URL$)Description
Instructs the specified ProGUI WebView widget (created with CreateWebView()) to navigate to a new URL.
Parameters
WebView
The handle of the ProGUI WebView widget.
URL$
The absolute URL (e.g., "https://www.example.com") or local file path
(e.g., "file:///C:/path/to/page.html") to navigate to.
Return Value
Returns #True if the navigation command was successfully
sent to the underlying WebView2 control, or #False if the
widget handle was invalid or not a WebView widget. Note that this does
not guarantee the navigation itself will succeed (e.g., due to network
errors or invalid URLs).
Remarks
This function provides the primary way to control the content displayed within a WebView widget after it has been created. Navigation is asynchronous.
Example
IncludeFile "ProGUI_PB.pbi"
StartProGUI()
Procedure NavigateButtonHandler(Widget, EventType, *EventData, WebViewWidget)
URL$ = InputRequester("Navigate", "Enter URL:", "https://www.purebasic.com")
If URL$
WebViewNavigate(WebViewWidget, URL$)
EndIf
EndProcedure
MyWindow = CreateWindow(0, 0, 800, 600, "WebView Navigation", #PG_Window_Default | #PG_Window_LayoutFlex) ; Create with a flex layout
LayoutFlexSetDirection(#Null, #PG_Flex_Direction_Column) ; Stack vertically
LayoutSetPadding(#Null, 10)
If MyWindow
; Button to trigger navigation
NavButton = CreateButton(0, 0, 150, 30, "Click to Navigate!")
; Create the WebView
MyWebView = CreateWebView(0, 0, 400, 400, "about:blank")
If MyWebView
WidgetSetMinWidth(MyWebView, 200)
WidgetSetMinHeight(MyWebView, 200)
WidgetSetMargin(MyWebView, 10)
; Set the button handler to control the WebView
AddEventHandler(NavButton, #PG_Event_Action, @NavigateButtonHandler(), MyWebView)
EndIf
WindowShow(MyWindow, #True, #PG_WindowShow_ScreenCentered)
Repeat
Event = WaitWindowEvent()
Until Event = #PB_Event_CloseWindow
EndIf
StopProGUI()See Also
Supported OS
Windows (Requires WebView2 Runtime)