The SetHomeUrl method assigns the home URL
associated with the specified browser. This URL is stored as part of
the client session and is used when the application calls
GoHome. Each browser instance maintains its own home URL,
independently of other instances.
The home URL may be any valid address supported by the WebView2
browser, including HTTP and HTTPS addresses, local file URLs, and URLs
referencing mapped virtual hosts. Leading whitespace is removed before
the URL is stored, but the address is not otherwise normalized or
validated. The URL must not exceed the maximum supported length of
5,119 characters, excluding the terminating null character. For
applications using UTF-8 encoding, the maximum length is measured in
bytes.
Passing a NULL pointer or an empty string clears the previously
defined home URL. If a new URL cannot be stored because of an invalid
parameter or insufficient memory, the existing home URL is preserved.
Setting the home URL does not initiate navigation or change the
currently displayed document. To navigate to the assigned home URL,
the application must explicitly call GoHome. The home
URL remains unchanged when navigating to other addresses and is
released when the browser is destroyed.
TCHAR szHomeUrl[INTERNET_MAX_URL_LENGTH] = _T("");
if (pWebView->SetHomeUrl(_T("https://www.example.com/")))
{
INT nLength = pWebView->GetHomeUrl(NULL, 0);
if (nLength > 0 && nLength < INTERNET_MAX_URL_LENGTH)
{
if (pWebView->GetHomeUrl(szHomeUrl, INTERNET_MAX_URL_LENGTH) > 0)
{
pWebView->GoHome();
}
}
}