Class Bookmark

  • 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.

Bookmark

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

MethodReturn typeBrief description
getId()StringGets the ID of theBookmark.
getPosition()PositionGets thePosition of theBookmark within theDocumentTab.
remove()voidDeletes theBookmark.

Detailed documentation

getId()

Gets the ID of theBookmark. The ID is unique within theDocumentTab.

Return

String — TheBookmark's ID, which is unique within theDocumentTab.

Authorization

Scripts that use this method require authorization with one or more of the followingscopes:

  • https://www.googleapis.com/auth/documents.currentonly
  • https://www.googleapis.com/auth/documents

getPosition()

Gets thePosition of theBookmark within theDocumentTab. 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.currentonly
  • https://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.currentonly
  • https://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.