Class Bookmark
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
บุ๊กมาร์ก
ออบเจ็กต์ที่แสดงถึงบุ๊กมาร์ก
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());
เอกสารประกอบโดยละเอียด
getId()
รับรหัสของ Bookmark
รหัสนี้จะไม่ซ้ำกันภายใน DocumentTab
รีเทิร์น
String
— รหัสของ Bookmark
ซึ่งไม่ซ้ำกันภายใน DocumentTab
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
getPosition()
รับ Position
ของ Bookmark
ภายใน DocumentTab
Position
จะยังคงถูกต้องตราบใดที่Bookmark
ไม่ถูกลบ แม้ว่าสคริปต์จะเปลี่ยนโครงสร้างเอกสารก็ตาม
รีเทิร์น
Position
— ตำแหน่งของ Bookmark
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
remove()
ลบ Bookmark
การเรียกใช้เมธอดนี้กับ Bookmark
ที่ลบไปแล้วจะไม่มีผล
การให้สิทธิ์
สคริปต์ที่ใช้วิธีการนี้ต้องได้รับอนุญาตด้วยขอบเขตต่อไปนี้อย่างน้อย 1 รายการ
-
https://www.googleapis.com/auth/documents.currentonly
-
https://www.googleapis.com/auth/documents
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-26 UTC
[null,null,["อัปเดตล่าสุด 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`"]]