CWebView::SetHomeUrl Method  
 
BOOL SetHomeUrl(
  LPCTSTR lpszHomeUrl  
);

The SetHomeUrl method changes the home URL for this browser instance.

Parameters

lpszHomeUrl
A null-terminated string which specifies the new home URL. If this parameter is NULL or an empty string, the current home URL will be deleted.

Return Value

If the method succeeds, the return value is non-zero. If the method fails, the return value is zero. To get extended error information, call WebViewGetLastError.

Remarks

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.

Example

TCHAR szHomeUrl[INTERNET_MAX_URL_LENGTH] = _T("");

// Assign the home URL for this WebView instance
if (pWebView->SetHomeUrl(_T("https://www.example.com/")))
{
    // Determine the length of the home URL
    INT nLength = pWebView->GetHomeUrl(NULL, 0);

    if (nLength > 0 && nLength < INTERNET_MAX_URL_LENGTH)
    {
        // Retrieve the home URL
        if (pWebView->GetHomeUrl(szHomeUrl, INTERNET_MAX_URL_LENGTH) > 0)
        {
            // Navigate to the assigned home URL
            pWebView->GoHome();
        }
    }
}

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: cshtmv12.lib
Unicode: Implemented as Unicode and ANSI versions

See Also