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

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

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:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business