# model/clipboard

Source: https://zotonic.com/cotonic/zotonic-models/clipboard

URI: https://zotonic.com/id/2752

Language: en



model/clipboard
===============

Copies text using the browser Clipboard API. Implemented in the wires script. Browser clipboard availability and permission rules still apply.

post/copy
---------

Topic: `model/clipboard/post/copy`.

Supply `{ text: "Text to copy" }` directly, or let a Cotonic DOM event provide `payload.message["data-text"]`. The `data-text` value takes precedence over `payload.text` when it is defined.

```javascript
cotonic.broker.publish("model/clipboard/post/copy", { text: "Example" });
```

A button can publish the command directly:

```html
<button type="button"
        data-onclick-topic="model/clipboard/post/copy"
        data-text="Example">Copy</button>
```

The handler does not return a reply or publish a success or failure event. A published command is therefore not confirmation that the copy succeeded. The direct `text` branch ignores empty strings.

Implementation
--------------

[JavaScript source](https://github.com/zotonic/zotonic/blob/master/apps/zotonic_mod_wires/priv/lib/js/apps/zotonic-wired.js).

License: 

Attribution: 

Related resources: https://zotonic.com/api/agent/related/2752?language=en


## API access

- [API help](<https://zotonic.com/api-help>)
- [OpenAPI specification](<https://zotonic.com/openapi.json>)
- [This resource as JSON](<https://zotonic.com/api/agent/resource/2752?language=en>)
