We use essential cookies for the website to function, as well as analytics cookies for analyzing and creating statistics of the website performance. To agree to the use of analytics cookies, click "Accept All". You can manage your preferences at any time by clicking "Cookie Settings" on the footer. More Information.

Only Essential Cookies
Accept All
quickApp ReferencesQuick AppAPISystem CapabilitiesClipboard

Clipboard

API Declaration

Add the following configuration to the features attribute in the manifest.json file:

Collapse
Word wrap
Dark theme
Copy code
  1. {"name": "system.clipboard"}

Module Import

Add the following configuration to the script element on the page where the API will be called:

Collapse
Word wrap
Dark theme
Copy code
  1. import clipboard from '@system.clipboard'

Or

Collapse
Word wrap
Dark theme
Copy code
  1. var clipboard = require("@system.clipboard")

Application Scope

Expand

Item

Description

Applicable devices

Mobile phones, tablets, Vision products, and telematics devices

Applicable regions

Global

Definition

Expand

API

Description

clipboard.set(OBJECT)

Modifies content on the clipboard.

clipboard.get(OBJECT)

Reads content from the clipboard.

clipboard.set(OBJECT)

Description

Modifies content on the clipboard.

OBJECT parameters

Expand

Parameter

Type

Mandatory

Description

text

string

Yes

Content that needs to be placed on the clipboard. If an empty character string ('') is passed, the clipboard will be cleared.

success

function

No

Callback upon success.

fail

function

No

Callback upon failure.

complete

function

No

Callback upon completion.

Sample code

Collapse
Word wrap
Dark theme
Copy code
  1. clipboard.set({
  2. text: 'text'
  3. })

clipboard.get(OBJECT)

Description

Reads content from the clipboard.

OBJECT parameters

Expand

Parameter

Type

Mandatory

Description

success

function

No

Callback upon success.

fail

function

No

Callback upon failure.

complete

function

No

Callback upon completion.

Parameters returned by success

Expand

Parameter

Type

Description

text

string

Content on the clipboard.

Sample code

Collapse
Word wrap
Dark theme
Copy code
  1. clipboard.get({
  2. success:function(data){
  3. console.log("handling success: " + data.text);
  4. },
  5. fail: function(data, code) {
  6. console.log("handling fail, code=" + code);
  7. }
  8. })

Demo

Collapse
Word wrap
Dark theme
Copy code
  1. <template>
  2. <div class="container">
  3. <div class="item-container">
  4. <div class="item-content">
  5. <text class="txt" if="{{show}}">{{clipboard}}</text>
  6. </div>
  7. <div class="item-content txt-left">
  8. <text class="txt">setClipboardtxt: {{showSet}}</text>
  9. <text class="txt">getClipboardtxt: {{showGet}}</text>
  10. </div>
  11. <input type="button" class="btn" onclick="set" value="Set Clipboard" />
  12. <input type="button" class="btn" onclick="get" value="Get Clipboard" />
  13. </div>
  14. </div>
  15. </template>
  16. <style>
  17. .container{
  18. flex: 1;
  19. flex-direction: column;
  20. }
  21. .item-container {
  22. margin-bottom: 50px;
  23. margin-right: 60px;
  24. margin-left: 60px;
  25. flex-direction: column;
  26. }
  27. .item-content {
  28. flex-direction: column;
  29. padding: 30px;
  30. margin-bottom: 50px;
  31. align-items: center;
  32. justify-content: center;
  33. }
  34. .txt {
  35. padding-top: 15px;
  36. padding-bottom: 15px;
  37. }
  38. .txt-left {
  39. align-items: flex-start;
  40. }
  41. .btn {
  42. height: 80px;
  43. text-align: center;
  44. border-radius: 5px;
  45. margin-right: 60px;
  46. margin-left: 60px;
  47. margin-bottom: 50px;
  48. color: #ffffff;
  49. font-size: 30px;
  50. background-color: #0faeff;
  51. }
  52. </style>
  53. <script>
  54. import clipboard from '@system.clipboard'
  55. export default {
  56. data: {
  57. show: true,
  58. clipboard: 'quick app',
  59. showSet: '',
  60. showGet: ''
  61. },
  62. onInit() {
  63. this.$page.setTitleBar({ text: 'clipboard' })
  64. },
  65. set: function () {
  66. this.showSet = this.clipboard
  67. clipboard.set({
  68. text: this.clipboard,
  69. success: function () {
  70. console.info('set success--- ')
  71. },
  72. fail: function () {
  73. console.info('set fail--- ')
  74. },
  75. complete: function () {
  76. console.info('set complete ')
  77. }
  78. })
  79. },
  80. get: function () {
  81. var that = this
  82. clipboard.get({
  83. success: function (obj) {
  84. that.showGet = obj.text
  85. },
  86. fail: function () {
  87. console.info('get fail--- ')
  88. },
  89. complete: function () {
  90. console.info('get complete ')
  91. }
  92. })
  93. }
  94. }
  95. </script>

The following figure shows the final effect.