书签
内容
使用chrome.bookmarks模块来创建、组织和管理书签。也可参看 Override Pages,来创建一个可定制的书签管理器页面。
介绍
您必须在扩展说明文件中声明使用书签API的权限。例如:
{ "name": "My extension", ... "permissions": [ "bookmarks" ], ... }
对象和属性
书签是按照树状结构组织的,每个节点都是一个书签或者一组节点(每个书签夹可包含多个节点)。每个节点都对应一个 BookmarkTreeNode 对象。
可以通过 chrome.bookmarks API来使用BookmarkTreeNode的属性。例如,当调用函数 create(),可以传入参数新节点的父节点(父节点ID),以及可选的节点索引,标题和url属性。可参看 BookmarkTreeNode 来获取节点的信息。
例子
下面的 代码创建了一个标题为 "Extension bookmarks"的书签夹。函数create()的第一个参数指定了新书签夹的属性,第二个参数定义了一个在书签夹创建后要执行的回调函数
chrome.bookmarks.create({'parentId': bookmarkBar.id, 'title': 'Extension bookmarks'}, function(newFolder) { console.log("added folder: " + newFolder.title); });
接下来的代码创建了一个指向扩展开发文档的书签。如果创建书签失败,也不会引起什么问题,所以没有指定回调函数。
chrome.bookmarks.create({'parentId': extensionsFolderId, 'title': 'Extensions doc', 'url': 'http://code.google.com/chrome/extensions'});
使用该API的实例请参看 basic bookmarks sample。其他例子和源码请参看 Samples。
API 参考:chrome.bookmarks
Properties
getLastError
chrome.extensionlastError方法
create
void chrome.bookmarks.create(, object bookmark, function callback)Undocumented.
在指定父节点下创建一个书签或者书签夹。如果url为空,则创建一个书签夹。
参数
- bookmark ( optional enumerated Type array of object )
- Undocumented.
- Description of this parameter from the json schema.
- This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
- parentId 父节点ID ( optional enumerated Type array of string )
- Undocumented.
- Description of this parameter from the json schema.
- This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
- index ( optional enumerated Type array of integer )
- Undocumented.
- Description of this parameter from the json schema.
- This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
- title ( optional enumerated Type array of string )
- Undocumented.
- Description of this parameter from the json schema.
- This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
- url ( optional enumerated Type array of string )
- Undocumented.
- Description of this parameter from the json schema.
- This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
- callback ( optional enumerated Type array of function )
- Undocumented.
- Description of this parameter from the json schema.
- This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
Returns
回调函数
The callback parameter should specify a function that looks like this:
如果需要指定回调函数,则回调函数格式如下:
function(BookmarkTreeNode result) {...};
- result ( optional enumerated BookmarkTreeNode array of paramType )
- Undocumented.
- Description of this parameter from the json schema.
- This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
This function was added in version . If you require this function, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
method name
void chrome.module.methodName(, )Undocumented.
A description from the json schema def of the function goes here.
Parameters
Returns
Callback function
The callback parameter should specify a function that looks like this:
If you specify the callback parameter, it should specify a function that looks like this:
function(Type param1, Type param2) {...};
This function was added in version . If you require this function, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
get
void chrome.bookmarks.get(, string or array of string idOrIdList, function callback)Undocumented.
获取指定的书签节点。
参数
- idOrIdList ( optional enumerated Type array of string or array of string )
- Undocumented.
- 一个字符串类型的Id,或者字符串数组
- This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
- callback ( optional enumerated Type array of function )
- Undocumented.
- Description of this parameter from the json schema.
- This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
Returns
回调函数
如果需要指定回调函数,则回调函数格式如下:
If you specify the callback parameter, it should specify a function that looks like this:
function(array of BookmarkTreeNode results) {...};
- results ( optional enumerated Type array of BookmarkTreeNode array of paramType paramType )
- Undocumented.
- Description of this parameter from the json schema.
- This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
This function was added in version . If you require this function, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
getChildren
void chrome.bookmarks.getChildren(, string id, function callback)Undocumented.
获取指定的书签节点的子节点
参数
- id ( optional enumerated Type array of string )
- Undocumented.
- Description of this parameter from the json schema.
- This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
- callback ( optional enumerated Type array of function )
- Undocumented.
- Description of this parameter from the json schema.
- This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
Returns
回调函数
如果需要指定回调函数,则回调函数格式如下:
If you specify the callback parameter, it should specify a function that looks like this:
function(array of BookmarkTreeNode results) {...};
- results ( optional enumerated Type array of BookmarkTreeNode array of paramType paramType )
- Undocumented.
- Description of this parameter from the json schema.
- This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
This function was added in version . If you require this function, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
getRecent
void chrome.bookmarks.getRecent(, integer numberOfItems, function callback)Undocumented.
获取最近添加的书签。
Parameters
- numberOfItems ( optional enumerated Type array of integer )
- Undocumented.
- 最多返回的条目数量。
- This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
- callback ( optional enumerated Type array of function )
- Undocumented.
- Description of this parameter from the json schema.
- This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
Returns
回调函数
如果需要指定回调函数,则回调函数格式如下:
If you specify the callback parameter, it should specify a function that looks like this:
function(array of BookmarkTreeNode results) {...};
- results ( optional enumerated Type array of BookmarkTreeNode array of paramType paramType )
- Undocumented.
- Description of this parameter from the json schema.
- This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
This function was added in version . If you require this function, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
getTree
void chrome.bookmarks.getTree(, function callback)Undocumented.
按照层次结构获取所有书签。
Parameters
- callback ( optional enumerated Type array of function )
- Undocumented.
- Description of this parameter from the json schema.
- This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
Returns
回调函数
回调参数 parameter 指定的回调函数如下:
If you specify the callback parameter, it should specify a function that looks like this:
function(array of BookmarkTreeNode results) {...};
- results ( optional enumerated Type array of BookmarkTreeNode array of paramType paramType )
- Undocumented.
- Description of this parameter from the json schema.
- This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
This function was added in version . If you require this function, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
method name
void chrome.module.methodName(, )Undocumented.
A description from the json schema def of the function goes here.
Parameters
Returns
Callback function
The callback parameter should specify a function that looks like this:
If you specify the callback parameter, it should specify a function that looks like this:
function(Type param1, Type param2) {...};
This function was added in version . If you require this function, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
move
void chrome.bookmarks.move(, string id, object destination, function callback)Undocumented.
移动指定的书签节点到指定的位置。
Parameters
- id ( optional enumerated Type array of string )
- Undocumented.
- Description of this parameter from the json schema.
- This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
- destination ( optional enumerated Type array of object )
- Undocumented.
- Description of this parameter from the json schema.
- This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the manifest key minimum_chrome_version can ensure that your extension won't be run in an earlier browser version.
- parentId ( optional enumerated Type array of string )
- Undocumented.
- Description of this parameter from the json schema.
- This parameter was added in version . You must omit this parameter in earlier versions, and you may omit it in any version. If you require this parameter, the mani