Export (0) Print
Expand All

AddFavorite Method

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

Syntax

external.AddFavorite(sURL [, sTitle])

Parameters

sURL Required. A String that specifies the URL of the favorite to add to the Favorites list.
sTitle Optional. 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 sTitle is not specified, sURL is used as the title of the favorite.

Return Value

No return value.

Remarks

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 sURL 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 sTitle 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 sTitle 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 sTitle are converted to hyphens (-), and leading and trailing spaces are trimmed. If no suitable characters are found in sTitle, 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.

Example

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);

Standards Information

There is no public standard that applies to this method.

Applies To

external

See Also

Community Additions

ADD
Show:
© 2014 Microsoft