IHTMLAnchorElement::href Property

Sets or retrieves a destination URL or an anchor point.


HRESULT IHTMLAnchorElement::get_href(BSTR *p);HRESULT IHTMLAnchorElement::put_href(BSTR v);


Pointer to a variable of type BSTR that receives the URL or anchor point.
BSTR that specifies the URL or anchor point.

Return Value

Returns S_OK if successful, or an error value otherwise.


When specified for an a element (also called an anchor element ), HREF defines a link to another document or another location within the document containing the a element. By default, the text between the opening and closing tags of the anchor element is underlined and the location specified by the HREF attribute is loaded when the user activates the link .

Note   You can use the Cascading Style Sheets (CSS) style rules to modify t he appearance of anchor elements .

The value of the HREF can be a URL that loads a separate document when the link is activated, or a frag ment identifier. Fragment identifiers, or bookmarks , define target locations within a document that are brought into view when links are activated. Use the NAME attribute of a separate anchor element to define a bookmark as a target location within a document .

Note   Generally, r elative URL s are resolved against the location of the document containing the a element. You can use the base element to control the resolution of relative URL s.

For more information on standard Internet protocols such as ftp, http, and mailto, see Predefined Protocols.

If HREF is specified as a blank value ( href="" or href=), executing the link might display the directory containing the current document , or it might generate an error, depending on other elements in the document and the server environment.

Note  As of Microsoft Internet Explorer 6  Service Pack 1 (SP1), browsing a local machine from the Internet zone is not allowed. For example, if an Internet site contains a link to a local file, Internet Explorer 6  SP1 and later displays a blank page when a user clicks on the link. Previous versions of Windows Internet Explorer followed the link to the local file.

Community Additions