Platform difference description for clipboard APIs

App H5 微信小程序 支付宝小程序 百度小程序 抖音小程序、飞书小程序 QQ小程序 快手小程序 京东小程序

# uni.setClipboardData(OBJECT)

Set the contents of the system clipboard.

OBJECT parameter description

Parameter Name Type Required Description Platform Difference Description
data String Yes what needs to be set
showToast Boolean No Configure whether to pop up a prompt, the default popup prompt App (3.2.13+), H5 (3.2.13+)
success Function No Callback for successful interface call
fail Function No Callback function for interface call failure
complete Function No The callback function of the end of the interface call (the call will be executed if the call succeeds or fails)

Example

uni.setClipboardData({
	data: 'hello',
	success: function () {
		console.log('success');
	}
});

# uni.getClipboardData(OBJECT)

Get the contents of the system clipboard.

OBJECT parameter description

Parameter name Type Required Instruction
success Function No Callback for successful interface calling
fail Function No Callback function for failed interface calling
complete Function No Callback function for closed interface calling (available both for successful and failed calling)

success return parameter description

Parameter Type Instruction
data String Contents of the clipboard

Example

uni.getClipboardData({
	success: function (res) {
		console.log(res.data);
	}
});

# Notice

  • 设置剪贴板内容后,小程序平台会自动弹出轻提示;(微信小程序在成功回调success里设置toast可覆盖自带的轻提示)。App平台默认与小程序保持一致策略。如不希望在App平台弹出提示,可使用Native.js自行操作剪贴板,插件市场有封装好的示例https://ext.dcloud.net.cn/plugin?id=712。也可以在设置剪切板后立即uni.hideToast()。

  • 如果小程序平台调用发现错误: setClipboardData:fail api scope is not declared in the privacy agreement, 原因是微信小程序于2023年9月15日更新剪切板为必须通过小程序后台配置用户隐私保护指引并审核通过后方可使用该API。