Share via


AddFavorite method

Deprecated. Prompts the user with a dialog box to add the specified URL to the Favorites list.

Syntax

var retval = external.AddFavorite(URL, Title);

Parameters

  • URL [in]
    Type: BSTR

    A String that specifies the URL of the favorite to add to the Favorites list.

  • Title [in, optional]
    Type: VARIANT

    Variant of type String that specifies the suggested title to use in the Favorites list. The user can change the title in the Add Favorite dialog box. If Title is not specified, URL is used as the title of the favorite.

Return value

Type: HRESULT

If this method succeeds, it returns S_OK. Otherwise, it returns an HRESULT error code.

Standards information

There are no standards that apply here.

Remarks

As of Internet Explorer 10, this method is deprecated and should no longer be used. In addition, this method is not supported for Windows Store apps using JavaScript and will fail silently if called.

Calling the AddFavorite method prompts the user with the same dialog box that is displayed when the user selects Add to Favorites from the Favorites menu.

The URL parameter must specify a valid URL using HTTP, Secure Hypertext Transfer Protocol (HTTPS), or File Transfer Protocol (FTP) protocols only. Calling the AddFavorite method with a file:// or javascript: URL returns a Permission Denied error.

Because the Title parameter is used as a file name when storing the favorite, it cannot contain characters that have been reserved by the file system. If present, the following characters are removed from Title before the Add a Favorite dialog box appears.

  • backslash (\)
  • apostrophe (*)
  • question mark (?)
  • double quotation mark (")
  • less than sign (<)
  • greater than sign (>)
  • pipe (|)

Additionally, slash marks (/) in Title are converted to hyphens (-), and leading and trailing spaces are trimmed. If no suitable characters are found in Title, the URL of the favorite is used instead.

If the favorites are stored on a drive that does not support long file names, only one dot (.) is allowed. Additionally, the title is trimmed to 8.3 and spaces are converted to hyphens.

This method is not supported in HTML Applications (HTAs).

Windows Internet Explorer 8 and later. For security reasons, the AddFavorite method must be called as a response to a user-initiated action, such a mouse click. If called from a different context, such as the onload event of the body element, the AddFavorite method fails silently.

Examples

This example uses the AddFavorite method to prompt a user to add the current page to the Favorites list. Because location.href is used, this script will succeed if served from a Web server using an allowed protocol, but fail with Permission Denied if run locally.

window.external.AddFavorite(location.href, document.title);

See also

external

Reference

IDM_ADDFAVORITES

Conceptual

How to Add a Shortcut Icon to a Web Page