All Products
Search
Document Center

Clipboard

Last Updated: Feb 04, 2021

my.getClipboard

Note: This interface is only supported in mPaaS 10.1.32 and later versions.

This interface is used to get the clipboard data.

Parameters

Parameter Type Required Description
success Function No Callback function upon call success.
fail Function No Callback function upon call failure.
complete Function No Callback function upon call completion (to be executed upon either call success or failure).

Return value on success

Name Type Description
text String Clipboard data

Sample code

  1. // API-DEMO page/API/clipboard/clipboard.json
  2. {
  3. "defaultTitle": "Clipboard"
  4. }
  1. <!-- API-DEMO page/API/clipboard/clipboard.axml-->
  2. <view class="page">
  3. <view class="page-section">
  4. <view class="page-section-title">setClipboard</view>
  5. <view class="page-section-demo">
  6. <input onInput="handleInput" value="{{text}}" />
  7. <button class="clipboard-button" type="primary" size="mini" onTap="handleCopy">Copy</button>
  8. </view>
  9. </view>
  10. <view class="page-section">
  11. <view class="page-section-title">getClipboard</view>
  12. <view class="page-section-demo">
  13. <input onInput="bindInput" value="{{copy}}" disabled />
  14. <button class="clipboard-button" type="default" size="mini" onTap="handlePaste">Paste</button>
  15. </view>
  16. </view>
  17. </view>
  1. // API-DEMO page/API/clipboard/clipboard.js
  2. Page({
  3. data: {
  4. text: '3.1415926',
  5. copy: '',
  6. },
  7. handleInput(e) {
  8. this.setData({
  9. text: e.detail.value,
  10. });
  11. },
  12. handleCopy() {
  13. my.setClipboard({
  14. text: this.data.text,
  15. });
  16. },
  17. handlePaste() {
  18. my.getClipboard({
  19. success: ({ text }) => {
  20. this.setData({ copy: text });
  21. },
  22. });
  23. },
  24. });
  1. /* API-DEMO page/API/clipboard/clipboard.acss */
  2. .clipboard-button {
  3. margin-left: 5px;
  4. }

my.setClipboard

Note: This interface is only supported in mPaaS 10.1.32 and later versions.

This interface is used to set the clipboard data.

Parameters

Parameter Type Required Description
text String Yes Clipboard data
success Function No Callback function upon call success.
fail Function No Callback function upon call failure.
complete Function No Callback function upon call completion (to be executed upon either call success or failure).

Sample code

  1. // API-DEMO page/API/clipboard/clipboard.json
  2. {
  3. "defaultTitle": "Clipboard"
  4. }
  1. <!-- API-DEMO page/API/clipboard/clipboard.axml-->
  2. <view class="page">
  3. <view class="page-section">
  4. <view class="page-section-title">setClipboard</view>
  5. <view class="page-section-demo">
  6. <input onInput="handleInput" value="{{text}}" />
  7. <button class="clipboard-button" type="primary" size="mini" onTap="handleCopy">Copy</button>
  8. </view>
  9. </view>
  10. <view class="page-section">
  11. <view class="page-section-title">getClipboard</view>
  12. <view class="page-section-demo">
  13. <input onInput="bindInput" value="{{copy}}" disabled />
  14. <button class="clipboard-button" type="default" size="mini" onTap="handlePaste">Paste</button>
  15. </view>
  16. </view>
  17. </view>
  1. // API-DEMO page/API/clipboard/clipboard.js
  2. Page({
  3. data: {
  4. text: '3.1415926',
  5. copy: '',
  6. },
  7. handleInput(e) {
  8. this.setData({
  9. text: e.detail.value,
  10. });
  11. },
  12. handleCopy() {
  13. my.setClipboard({
  14. text: this.data.text,
  15. });
  16. },
  17. handlePaste() {
  18. my.getClipboard({
  19. success: ({ text }) => {
  20. this.setData({ copy: text });
  21. },
  22. });
  23. },
  24. });
  1. /* API-DEMO page/API/clipboard/clipboard.acss */
  2. .clipboard-button {
  3. margin-left: 5px;
  4. }