Visit Mozilla.org

FUEL:Annotations

From MDC

This article covers features introduced in Firefox 3

The annotation service is designed to store arbitrary data about a web page in Firefox 3

Contents

[edit] Method overview

boolean has(in AString aName)
nsIVariant get(in AString aName)
void set(in AString aName, in nsIVariant aValue, in PRInt32 aExpiration)
void remove(in AString aName)

[edit] Attributes

Attribute Type Description
names readonly attribute nsIVariant Array of the annotation names associated with the owning item

[edit] Methods

[edit] has()

Determines if an annotation exists with the given name.

boolean has(in AString aName)

[edit] Parameters

aName
The name of the annotation

[edit] Return value

true if an annotation exists with the given name, false otherwise.

[edit] get()

Gets the value of an annotation with the given name.

nsIVariant get(in AString aName)

[edit] Parameters

aName
The name of the annotation

[edit] Return value

A variant containing the value of the annotation. Supports string, boolean and number.

[edit] set()

Sets the value of an annotation with the given name.

void set(in AString aName, in nsIVariant aValue, in PRInt32 aExpiration)

[edit] Parameters

aName
The name of the annotation
aValue
The new value of the annotation. Supports string, boolean and number.
aExpiration
The expiration policy for the annotation. See nsIAnnotationService.

[edit] Return value

[edit] remove()

Removes the named annotation from the owner item.

void remove(in AString aName)

[edit] Parameters

aName
The name of annotation.

[edit] Return value

[edit] Examples

const NEVER_EXPIRE = 0;

function url(spec) {
  var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
  return ios.newURI(spec, null, null);
}

var bookmark = Application.bookmarks.menu.addBookmark("Mozilla", url("http://www.mozilla.com/"));
bookmark.annotations.set("mystuff/public", true, NEVER_EXPIRE);
bookmark.annotations.set("mystuff/rating", 5, NEVER_EXPIRE);

alert(bookmark.annotations.get("mystuff/rating"));

bookmark.annotations.remove("mystuff/rating");

[edit] See also