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

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Eclipse Helios Update Brings New PHP Tools
Internet Explorer 9 Ups Standards Support
JBoss Portal 5 Release Easier to Use

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:

<SCRIPT LANGUAGE="JavaScript">
<!--

function addBookmark() {
  if (window.external)
    external.AddFavorite(location.href)
  else
    alert("Your browser doesn't support this feature.");
}

// -->
</SCRIPT>
<FORM>
<INPUT TYPE="button" VALUE="Add" onClick="addBookmark()">
</FORM>

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)


People who read this tip also read these tips:

Look for similar tips by subject:

webref The latest from WebReference.com Browse >
Flashmaps' DynamicLocator: Interactive Maps for Small Areas · Flashmaps' AreaSelector: Interactive Maps for Wide Areas · The DB Mapper: Interactive Street-level Maps of U.S. and Canada
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
MS Access and MySQL · Cisco AutoQoS: VoIP QoS for Mere Mortals · While VoIP Adoption Explodes in Enterprise, Carrier Spending Lags