Class Bookmark Stay organized with collections Save and categorize content based on your preferences.
AI-generated Key Takeaways
A Bookmark object represents a bookmark in a Google Document.
You can add a bookmark at the cursor position in the active document tab.
Bookmark objects have methods to get their ID and position, and to remove themselves.
An object representing a bookmark.
constdoc=DocumentApp.getActiveDocument();constdocumentTab=doc.getActiveTab().asDocumentTab();// Insert a bookmark at the cursor position (in the active tab) and log its ID.constcursor=doc.getCursor();constbookmark=documentTab.addBookmark(cursor);Logger.log(bookmark.getId());
Methods
| Method | Return type | Brief description |
|---|---|---|
get | String | Gets the ID of theBookmark. |
get | Position | Gets thePosition of theBookmark within theDocument. |
remove() | void | Deletes theBookmark. |
Detailed documentation
getId()
Gets the ID of theBookmark. The ID is unique within theDocument.
Return
String — TheBookmark's ID, which is unique within theDocument.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/documents.currentonlyhttps://www.googleapis.com/auth/documents
getPosition()
Gets thePosition of theBookmark within theDocument. ThePosition remains accurate so long as theBookmark is not deleted, even if the scriptchanges the document structure.
Return
Position — The position of theBookmark.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/documents.currentonlyhttps://www.googleapis.com/auth/documents
remove()
Deletes theBookmark. Calling this method on aBookmark that has already beendeleted has no effect.
Authorization
Scripts that use this method require authorization with one or more of the followingscopes:
https://www.googleapis.com/auth/documents.currentonlyhttps://www.googleapis.com/auth/documents
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-12-02 UTC.