November 27, 1999 - Adding a Favorite | WebReference

November 27, 1999 - Adding a Favorite

Yehuda Shiran November 27, 1999
Adding a Favorite
Tips: November 1999

Yehuda Shiran, Ph.D.
Doc JavaScript

The external object's AddFavorite() method in Internet Explorer 4 and above prompts the user with a dialog box to add the specified URL to the Favorites list. Even though this technique doesn't automatically get you into the user's list, it gives you a much better chance. The method's general syntax is:

external.AddFavorite(sURL [, sTitle]);

The first argument specifies the URL to be added to the Favorites menu. The second argument (optional) specifies the title of the specified page. If you don't explicitly state a title, the default title is the URL. It can be changed by the user in the dialog box that pops up when the method is executed. The following code segment adds the current page to the Favorites list:

function addBookmark() {
  if (window.external)
    alert("Your browser doesn't support this feature.");
// -->
<INPUT TYPE="button" VALUE="Add" onClick="addBookmark()">

Here's the actual output:

Note that the external object and the AddFavorite() method aren't supported by Netscape Navigator. Therefore, we must make sure the user is running a browser that supports this method:

if (window.external)