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

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs

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, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint