The GetDocumentLength method returns the number of characters
in the current document. This will reflect the state of the document
at the time the method is called. If the page has been dynamically
modified by scripts after it was initially loaded, those changes will
be included. Note that if your project is configured to use Unicode,
this value will not be the same as the size of the document in bytes.
This method should only be called after navigation has completed.
If called while a page is still loading, the contents of the page may
be incomplete or empty. The length of the document includes the HTML
markup and inline scripting.
If a blank page is currently being displayed, such as when
navigating to about:blank or by setting the current document
text to an empty string, this method can still return a value.
Internally, the browser creates a blank page using the markup
"<html><head></head><body></body></html>"
and this method will return the length of that content.
The GetFilteredText method can be used to obtain a
filtered version of the text with the HTML markup removed.
INT nLength = pWebView->GetDocumentLength();
if (nLength > 0)
{
LPTSTR pszBuffer = (LPTSTR)malloc((nLength + 1) * sizeof(TCHAR));
if (!pszBuffer)
{
return;
}
nLength = pWebView->GetDocumentText(pszBuffer, nLength + 1);
if (nLength > 0)
{
_putts(pszBuffer);
_puttc(_T('\n'), stdout);
}
free(pszBuffer);
}