> ## Documentation Index
> Fetch the complete documentation index at: https://docs.median.co/llms.txt
> Use this file to discover all available pages before exploring further.

# Clipboard

> Read and write the device clipboard.

Access the device clipboard from your web app using the Median JavaScript Bridge. You can write text to the clipboard and read the current clipboard contents.

> [!TIP]
>
> **Developer Demo**
>
> Try it live: Load [https://median.dev/clipboard/](https://median.dev/clipboard/) in your Median app to test clipboard functionality during development.

The `median.clipboard` API exposes two methods:

| Method | Description |
| - | - |
| `median.clipboard.set()` | Writes a string to the device clipboard |
| `median.clipboard.get()` | Reads the current clipboard contents |

Both iOS and Android are supported. `clipboard.get()` supports two async patterns: Promises and named callback functions.

## Implementation guide

### Writing to the clipboard

Use `median.clipboard.set()` to copy a string to the system clipboard. This is the equivalent of a user pressing Ctrl+C / Cmd+C on their desktop browser.

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.clipboard.set({ data: "Text to copy" });
```

**Parameter**

| Key | Type | Required | Description |
| - | - | - | - |
| `data` | `string` | Yes | The text string to write to the clipboard |

**Example use case**: Providing a "Copy to clipboard" button for invite codes, promo codes, links, or other content.

Median JavaScript Bridge

```javascript JavaScript theme={null}
document.getElementById("copy-btn").addEventListener("click", function () {
  median.clipboard.set({ data: "PROMO2024" });
});
```

### Reading from the clipboard

Use `median.clipboard.get()` to retrieve the current clipboard contents. This method is asynchronous and returns a result object with either a data property (on success) or an error property (on failure).

Choose the pattern that best fits your codebase: promises or callbacks.

#### Option 1: Promise (recommended)

Promises integrate cleanly with async/await and modern JavaScript workflows.

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.clipboard.get().then(function (result) {
  if (result.data) {
    console.log("Clipboard contents:", result.data);
  } else {
    console.error("Clipboard error:", result.error);
  }
});

// Using async/await

async function readClipboard() {
const result = await median.clipboard.get();

    if (result.data) {
      console.log("Clipboard contents:", result.data);
    } else {
      console.error("Clipboard error:", result.error);
    }

}
```

#### Option 2: Named callback

Named callbacks are useful when integrating with legacy codebases or when you need the function to be callable from native app contexts.

Pass the name of your callback function as a string using the callback key:

Median JavaScript Bridge

```javascript JavaScript theme={null}
median.clipboard.get({ callback: "clipboardCallback" });

function clipboardCallback(result) {
  if (result.data) {
    console.log("Clipboard contents:", result.data);
  } else {
    console.error("Clipboard error:", result.error);
  }
}
```

**Response object**

Both `clipboard.get()` patterns return the same result object:

| Property | Type | Description |
| - | - | - |
| `data` | `string` | The clipboard text content. Present on success. |
| `error` | `string` | An error message. Present when the clipboard could not be read. |

Always check for `result.data` before using the value, and handle the `result.error` case.

## Platform behavior

* **iOS**: On iOS 14+, the system may display a notification banner informing the user that your app has accessed the clipboard. This is an OS-level behavior and cannot be suppressed.
* **Android**: Clipboard read access may be restricted on Android 10+ when your app is not in the foreground. Ensure clipboard reads are triggered by an explicit user action.


## Related topics

- [Install Median's GTM tag template](https://docs.median.co/docs/install-median-gtm-template.md)
- [Enterprise overview](https://docs.median.co/docs/enterprise.md)
- [Link behavior](https://docs.median.co/docs/internal-vs-external-links.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.