CWebView::GetCurrentUrl Method  
 
BOOL GetCurrentUrl(
  LPTSTR lpszUrl,  
  INT nMaxLength  
);

The GetCurrentUrl method returns the URL for the current document.

Parameters

lpszUrl
A string buffer which will contain the current URL when the function returns. If this parameter is NULL, the method will not copy anything into the buffer but will return the length of the URL, not including the terminating null character. If a buffer is provided, it must be large enough to contain the entire URL.
nMaxLength
An integer which specifies the maximum number of characters which can be copied into the string buffer, including the terminating null. If the lpszUrl parameter is NULL this value should be zero.

Return Value

If the method succeeds, the return value is the length of the current URL, not including the terminating null. If the method fails, the return value is zero. To get extended error information, call GetLastError.

Remarks

The GetCurrentUrl method retrieves the URL associated with the current document loaded in the browser instance. The URL value is available as soon as navigation begins to a new location, so it can be queried during or after the navigation process. This allows applications to obtain the destination address immediately, even before the page has fully loaded or rendered its content.

Note that the current URL may differ from the value originally passed to Navigate. The browser engine can normalize the address, such as adjusting letter case, expanding relative paths, or adding default components like a trailing slash. In addition, the current URL can change multiple times during the course of a navigation if the server issues one or more HTTP redirects before the final document is retrieved. For this reason, the URL returned by this method should be treated as the authoritative location of the content currently being displayed.

This method differs from examining the document itself (for example, by executing a script to query document.URL) because it reflects the navigation state maintained internally by the control. Applications should use this method to reliably track the current location of the browser instance.

If the SetDocumentText method was called to change the current document, the URL returned by this method will typically be "data:text/html" which indicates it is a local data source.

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