Class Bookmark
Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Aggiungi ai preferiti
Un oggetto che rappresenta un preferito.
const doc = DocumentApp.getActiveDocument();
const documentTab = doc.getActiveTab().asDocumentTab();
// Insert a bookmark at the cursor position (in the active tab) and log its ID.
const cursor = doc.getCursor();
const bookmark = documentTab.addBookmark(cursor);
Logger.log(bookmark.getId());
Documentazione dettagliata
getId()
Recupera l'ID del Bookmark
. L'ID è univoco all'interno di DocumentTab
.
Invio
String
: l'ID di Bookmark
, univoco all'interno di DocumentTab
.
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getPosition()
Recupera il Position
del Bookmark
all'interno del DocumentTab
. Il valore Position
rimane preciso finché Bookmark
non viene eliminato, anche se lo script
modifica la struttura del documento.
Invio
Position
: la posizione del Bookmark
.
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
remove()
Consente di eliminare l'elemento Bookmark
. La chiamata di questo metodo su un Bookmark
già eliminato non ha alcun effetto.
Autorizzazione
Gli script che utilizzano questo metodo richiedono l'autorizzazione con uno o più dei seguenti ambiti:
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
Salvo quando diversamente specificato, i contenuti di questa pagina sono concessi in base alla licenza Creative Commons Attribution 4.0, mentre gli esempi di codice sono concessi in base alla licenza Apache 2.0. Per ulteriori dettagli, consulta le norme del sito di Google Developers. Java è un marchio registrato di Oracle e/o delle sue consociate.
Ultimo aggiornamento 2025-07-26 UTC.
[null,null,["Ultimo aggiornamento 2025-07-26 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,["# Class Bookmark\n\nBookmark\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\n### Methods\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\n### `get``Id()`\n\nGets the ID of the `Bookmark`. The ID is unique within the [DocumentTab](/apps-script/reference/document/document-tab).\n\n#### Return\n\n\n`String` --- The `Bookmark`'s ID, which is unique within the `Document``Tab`.\n\n#### Authorization\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()`\n\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\n#### Return\n\n\n[Position](/apps-script/reference/document/position) --- The position of the `Bookmark`.\n\n#### Authorization\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()`\n\nDeletes the `Bookmark`. Calling this method on a `Bookmark` that has already been\ndeleted has no effect.\n\n#### Authorization\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`"]]