Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

userAgent property

Retrieves a string equivalent to the HTTP user-agent request header.

Syntax

HRESULT value = object.get_userAgent(* p);

Property values

Type: BSTR

BSTR that specifies a valid HTTP user agent.

Remarks

The user-agent request header contains information about compatibility, the client, and the platform name. For more information about retrieving the application name, see the IOmNavigator::appName property. For more information about the platform and version, see the IOmNavigator::appVersion property.

The IOmNavigator::userAgent property dynamically returns a different value depending on the browser and platform versions.

For example, Microsoft Internet Explorer 6 returns the following string for Windows XP.


Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)

Examples

The following function retrieves the user agent string and returns it through the out parameter, pbstrUA.


// Equivalent to document.parentWindow.navigator.userAgent
HRESULT GetUA(IHTMLDocument2* pDoc, BSTR* pbstrUA)
{
   IHTMLWindow2* pWindow = NULL;

   if (!pDoc)
   {
      return E_INVALIDARG;
   }

   hr = pDoc->get_parentWindow(&pWindow);
   if (FAILED(hr) || !pWindow)
   {
      return hr;
   }

   IOmNavigator* pNavigator = NULL;
   hr = pWindow->get_navigator(&pNavigator);
   if (FAILED(hr) || !pNavigator)
   {
      goto Error;
   }

   hr = pNavigator->get_userAgent(pbstrUA);

Error:
	if (pWindow) pWindow->Release();
	if (pNavigator) pNavigator->Release();
	return hr;
}


See also

About Conditional Comments

 

 

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.