Search.../

copyToClipboard( )

Copies text to the site visitor's clipboard.

Description

The copyToClipboard() function copies the specified text to the site visitor's clipboard.

If the site visitor's browser does not support copying text to the clipboard programmatically, a modal popup that allows copying will be displayed. For example, when calling copyToClipboard from a Firefox or Edge browser the site visitor will see something similar to the popup shown below.

Copy To Clipboard Popup

The Promise returned by copyToClipboard() resolves when the specified text is copied to clipboard or the modal popup is closed. The Promise is rejected if a null value is passed as the toCopy parameter or if the visitor's browser blocks the modal popup from opening.

Syntax

function copyToClipboard(text: string): Promise<void>

copyToClipboard Parameters

NAME
TYPE
DESCRIPTION
text
string

The text to copy.

Returns

Fulfilled - When the copy is complete or the site visitor closes the modal popup.

Return Type:

Promise<void>

Was this helpful?

Copy text to clipboard

Copy Code
1import wixWindowFrontend from 'wix-window-frontend';
2
3// ...
4
5wixWindowFrontend.copyToClipboard("Text to copy!")
6 .then( () => {
7 // handle case where text was copied
8 } )
9 .catch( (err) => {
10 // handle case where an error occurred
11 } );