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.
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
The text to copy.
Returns
Fulfilled - When the copy is complete or the site visitor closes the modal popup.
Return Type:
Was this helpful?
Copy text to clipboard
1import wixWindowFrontend from 'wix-window-frontend';23// ...45wixWindowFrontend.copyToClipboard("Text to copy!")6 .then( () => {7 // handle case where text was copied8 } )9 .catch( (err) => {10 // handle case where an error occurred11 } );