Stay organized with collections
Save and categorize content based on your preferences.
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());
Gets the Position of the Bookmark within the DocumentTab. The Position remains accurate so long as the Bookmark is not deleted, even if the script
changes the document structure.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2024-12-02 UTC."],[[["\u003cp\u003eA Bookmark object represents a specific location within a Google Doc, allowing you to programmatically interact with it.\u003c/p\u003e\n"],["\u003cp\u003eYou can create a Bookmark using the \u003ccode\u003eaddBookmark()\u003c/code\u003e method of a DocumentTab, inserting it at the current cursor position.\u003c/p\u003e\n"],["\u003cp\u003eBookmarks offer methods to retrieve their unique ID (\u003ccode\u003egetId()\u003c/code\u003e), get their position within the document (\u003ccode\u003egetPosition()\u003c/code\u003e), and remove them (\u003ccode\u003eremove()\u003c/code\u003e).\u003c/p\u003e\n"],["\u003cp\u003eBookmark positions remain valid even after document modifications, unless the bookmark itself is deleted.\u003c/p\u003e\n"]]],[],null,["Bookmark\n\nAn object representing a bookmark.\n\n```javascript\nconst doc = DocumentApp.getActiveDocument();\nconst documentTab = doc.getActiveTab().asDocumentTab();\n\n// Insert a bookmark at the cursor position (in the active tab) and log its ID.\nconst cursor = doc.getCursor();\nconst bookmark = documentTab.addBookmark(cursor);\nLogger.log(bookmark.getId());\n``` \n\nMethods\n\n| Method | Return type | Brief description |\n|---------------------------------|------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------|\n| [getId()](#getId()) | `String` | Gets the ID of the `Bookmark`. |\n| [getPosition()](#getPosition()) | [Position](/apps-script/reference/document/position) | Gets the [Position](/apps-script/reference/document/position) of the `Bookmark` within the [DocumentTab](/apps-script/reference/document/document-tab). |\n| [remove()](#remove()) | `void` | Deletes the `Bookmark`. |\n\nDetailed documentation \n\n`get``Id()` \nGets the ID of the `Bookmark`. The ID is unique within the [DocumentTab](/apps-script/reference/document/document-tab).\n\nReturn\n\n\n`String` --- The `Bookmark`'s ID, which is unique within the `Document``Tab`.\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/documents.currentonly`\n- `https://www.googleapis.com/auth/documents`\n\n*** ** * ** ***\n\n`get``Position()` \nGets the [Position](/apps-script/reference/document/position) of the `Bookmark` within the [DocumentTab](/apps-script/reference/document/document-tab). The `Position` remains accurate so long as the `Bookmark` is not deleted, even if the script\nchanges the document structure.\n\nReturn\n\n\n[Position](/apps-script/reference/document/position) --- The position of the `Bookmark`.\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/documents.currentonly`\n- `https://www.googleapis.com/auth/documents`\n\n*** ** * ** ***\n\n`remove()` \nDeletes the `Bookmark`. Calling this method on a `Bookmark` that has already been\ndeleted has no effect.\n\nAuthorization\n\nScripts that use this method require authorization with one or more of the following [scopes](/apps-script/concepts/scopes#setting_explicit_scopes):\n\n- `https://www.googleapis.com/auth/documents.currentonly`\n- `https://www.googleapis.com/auth/documents`"]]