WebViewNavigate

Syntax

Success = WebViewNavigate(WebViewWidget, URL$)

Description

Instructs the specified ProGUI WebView widget (created with CreateWebView()) to navigate to a new URL.

Parameters

WebViewWidget
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)
  If EventType = #PG_Event_MouseLeftButtonUp
    URL$ = InputRequester("Navigate", "Enter URL:", "https://www.purebasic.com")
    If URL$
        WebViewNavigate(WebViewWidget, URL$)
    EndIf
  EndIf
EndProcedure

MyWindow = CreateWindow(0, 0, 800, 600, "WebView Navigation")
RootLayout = WindowGetLayout(MyWindow)
LayoutSetType(RootLayout, #PG_Layout_Type_Flex)
LayoutFlexSetDirection(RootLayout, #PG_Flex_Direction_Column) ; Stack vertically
LayoutSetPadding(RootLayout, 10)

If MyWindow
  ; Button to trigger navigation
  NavButton = CreateWidget(0, 0, 100, 30)
  WidgetSetClass(NavButton, "button") ; Assume skin exists
  ; Add a drawing handler or text for the button

  ; 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_MouseLeftButtonUp, @NavigateButtonHandler(), MyWebView)
  EndIf

  WindowShow(MyWindow, #True, #PG_Window_ScreenCentered)

  Repeat
    Event = WaitWindowEvent()
  Until Event = #PB_Event_CloseWindow
EndIf

StopProGUI()

See Also

CreateWebView

Supported OS

Windows (Requires WebView2 Runtime)