Class OpenLink
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เปิดลิงก์
แสดงการดำเนินการเพื่อเปิดลิงก์ที่มีตัวเลือกบางอย่าง
พร้อมใช้งานสำหรับส่วนเสริมของ Google Workspace และแอป Google Chat
// A button that opens as a link in an overlay and
// requires a reload when closed.
const button = CardService.newTextButton()
.setText('This button opens a link in an overlay window')
.setOpenLink(
CardService.newOpenLink()
.setUrl('https://www.google.com')
.setOpenAs(CardService.OpenAs.OVERLAY)
.setOnClose(CardService.OnClose.RELOAD_ADD_ON),
);
// An action response that opens a link in full screen and
// requires no action when closed.
const actionResponse = CardService.newActionResponseBuilder()
.setOpenLink(
CardService.newOpenLink()
.setUrl('https://www.google.com')
.setOpenAs(CardService.OpenAs.FULL_SIZE)
.setOnClose(CardService.OnClose.NOTHING),
)
.build();
หมายเหตุ: หากต้องการโหลดส่วนเสริมซ้ำหลังจากปิดลิงก์ อย่าใช้ลิงก์ที่เปิดใช้ส่วนหัว Cross-Origin-Opener-Policy (COOP) หากเปิดใช้ COOP ในลิงก์ ส่วนเสริมจะตรวจจับสถานะหน้าต่างไม่ได้และการ์ดส่วนเสริมจะไม่อัปเดต
เอกสารประกอบโดยละเอียด
setOnClose(onClose)
ตั้งค่าลักษณะการทํางานของ URL เมื่อปิดหน้าต่างหรือแท็บ URL
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
onClose | OnClose | การตั้งค่าการปิด |
รีเทิร์น
OpenLink
— ออบเจ็กต์นี้สําหรับการต่อเชื่อม
setOpenAs(openAs)
ตั้งค่าลักษณะการทํางานของ URL เมื่อเปิด
พารามิเตอร์
ชื่อ | ประเภท | คำอธิบาย |
openAs | OpenAs | การตั้งค่าการเปิด |
รีเทิร์น
OpenLink
— ออบเจ็กต์นี้สําหรับการต่อเชื่อม
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-26 UTC
[null,null,["อัปเดตล่าสุด 2025-07-26 UTC"],[[["\u003cp\u003e\u003ccode\u003eOpenLink\u003c/code\u003e allows Google Workspace Add-ons and Google Chat apps to open specified URLs with customizable behaviors.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can set how the link opens (overlay or full-screen) and the action taken when it's closed (reload add-on or do nothing).\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eOpenLink\u003c/code\u003e object provides methods like \u003ccode\u003esetOnClose\u003c/code\u003e, \u003ccode\u003esetOpenAs\u003c/code\u003e, and \u003ccode\u003esetUrl\u003c/code\u003e for configuration.\u003c/p\u003e\n"],["\u003cp\u003eWhen using \u003ccode\u003esetOnClose\u003c/code\u003e to reload add-ons, avoid links with Cross-Origin-Opener-Policy (COOP) enabled for proper functionality.\u003c/p\u003e\n"]]],[],null,["# Class OpenLink\n\nOpenLink\n\nRepresents an action to open a link with some options.\n\nAvailable for Google Workspace add-ons and Google Chat apps.\n\n```javascript\n// A button that opens as a link in an overlay and\n// requires a reload when closed.\nconst button = CardService.newTextButton()\n .setText('This button opens a link in an overlay window')\n .setOpenLink(\n CardService.newOpenLink()\n .setUrl('https://www.google.com')\n .setOpenAs(CardService.OpenAs.OVERLAY)\n .setOnClose(CardService.OnClose.RELOAD_ADD_ON),\n );\n\n// An action response that opens a link in full screen and\n// requires no action when closed.\nconst actionResponse = CardService.newActionResponseBuilder()\n .setOpenLink(\n CardService.newOpenLink()\n .setUrl('https://www.google.com')\n .setOpenAs(CardService.OpenAs.FULL_SIZE)\n .setOnClose(CardService.OnClose.NOTHING),\n )\n .build();\n```\n\n\n**Note:** To reload add-ons after closing a link, don't use a link with\nCross-Origin-Opener-Policy (COOP) header enabled. If COOP is enabled in a link, add-ons can't\ndetect the window state, and the add-on card doesn't update. \n\n### Methods\n\n| Method | Return type | Brief description |\n|---------------------------------------------|---------------|---------------------------------------------------------------------------|\n| [setOnClose(onClose)](#setOnClose(OnClose)) | [OpenLink](#) | Sets the behavior of the URL action when the URL window or tab is closed. |\n| [setOpenAs(openAs)](#setOpenAs(OpenAs)) | [OpenLink](#) | Sets the behavior of URL when it is opened. |\n| [setUrl(url)](#setUrl(String)) | [OpenLink](#) | Sets the URL to be opened. |\n\nDetailed documentation\n----------------------\n\n### `set``On``Close(onClose)`\n\nSets the behavior of the URL action when the URL window or tab is closed.\n\n#### Parameters\n\n| Name | Type | Description |\n|-------------|---------------------------------------------------------|----------------------|\n| `on``Close` | [OnClose](/apps-script/reference/card-service/on-close) | The closing setting. |\n\n#### Return\n\n\n[OpenLink](#) --- This object, for chaining.\n\n*** ** * ** ***\n\n### `set``Open``As(openAs)`\n\nSets the behavior of URL when it is opened.\n\n#### Parameters\n\n| Name | Type | Description |\n|------------|-------------------------------------------------------|----------------------|\n| `open``As` | [OpenAs](/apps-script/reference/card-service/open-as) | The opening setting. |\n\n#### Return\n\n\n[OpenLink](#) --- This object, for chaining.\n\n*** ** * ** ***\n\n### `set``Url(url)`\n\nSets the URL to be opened. The URL must match a prefix [whitelisted in\nthe manifest](/gmail/add-ons/concepts/manifests#manifest_structure_for_gmail_add-ons).\n\n#### Parameters\n\n| Name | Type | Description |\n|-------|----------|------------------|\n| `url` | `String` | The URL to open. |\n\n#### Return\n\n\n[OpenLink](#) --- This object, for chaining."]]