OpenLink

Represents an action to open a link with some options.

Available for Google Workspace add-ons and Google Chat apps.

```javascript
// 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();
```


**Note:** To reload add-ons after closing a link, don't use a link with
Cross-Origin-Opener-Policy (COOP) header enabled. If COOP is enabled in a link, add-ons can't
detect the window state, and the add-on card doesn't update.

### Methods

| Method | Return type | Brief description |
|---|---|---|
| `https://developers.google.com/apps-script/reference/card-service/open-link#setOnClose(OnClose)` | `https://developers.google.com/apps-script/reference/card-service/open-link#` | Sets the behavior of the URL action when the URL window or tab is closed. |
| `https://developers.google.com/apps-script/reference/card-service/open-link#setOpenAs(OpenAs)` | `https://developers.google.com/apps-script/reference/card-service/open-link#` | Sets the behavior of URL when it is opened. |
| `https://developers.google.com/apps-script/reference/card-service/open-link#setUrl(String)` | `https://developers.google.com/apps-script/reference/card-service/open-link#` | Sets the URL to be opened. |

## Detailed documentation

### `setOnClose(onClose)`

Sets the behavior of the URL action when the URL window or tab is closed.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `onClose` | `https://developers.google.com/apps-script/reference/card-service/on-close` | The closing setting. |

#### Return


`https://developers.google.com/apps-script/reference/card-service/open-link#` --- This object, for chaining.

*** ** * ** ***

### `setOpenAs(openAs)`

Sets the behavior of URL when it is opened.

#### Parameters

| Name | Type | Description |
|---|---|---|
| `openAs` | `https://developers.google.com/apps-script/reference/card-service/open-as` | The opening setting. |

#### Return


`https://developers.google.com/apps-script/reference/card-service/open-link#` --- This object, for chaining.

*** ** * ** ***

### `setUrl(url)`

Sets the URL to be opened. The URL must match a prefix [in the manifest allowlist](https://developers.google.com/workspace/add-ons/concepts/workspace-manifests#allowlist).

#### Parameters

| Name | Type | Description |
|---|---|---|
| `url` | `String` | The URL to open. |

#### Return


`https://developers.google.com/apps-script/reference/card-service/open-link#` --- This object, for chaining.