Device APIs

Clipboard

Get and set clipboard data.

Overview

The clipboard APIs allow you to read from and write to the system clipboard, enabling copy and paste functionality within your mini program.

my.getClipboard

Retrieves the current content of the clipboard.

Sample Code

my.getClipboard({
  success: (res) => {
    my.alert({
      content: res.text
    });
  },
});

Parameters

PropertyTypeRequiredDescription
successFunctionNoCallback function upon call success.
failFunctionNoCallback function upon call failure.
completeFunctionNoCallback function upon call completion (to be executed upon either call success or failure).

Success Callback Function

PropertyTypeDescription
textStringClipboard content.

my.setClipboard

Sets text content to the clipboard.

Sample Code

my.setClipboard({
  text: 'copy content',
  success: () => {
    my.alert({
      content: 'Copied successfully'
    });
  },
});

Parameters

PropertyTypeRequiredDescription
textStringYesThe text content to copy to clipboard.
successFunctionNoCallback function upon call success.
failFunctionNoCallback function upon call failure.
completeFunctionNoCallback function upon call completion (to be executed upon either call success or failure).

Usage Notes

  • my.setClipboard overwrites any existing clipboard content
  • my.getClipboard retrieves text content only
  • Clipboard operations are synchronous from the user's perspective
  • Useful for implementing copy-to-clipboard features
  • Consider showing user feedback when clipboard operations complete