You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -28,56 +22,106 @@ The `clipboard` module has the following methods:
28
22
29
23
### `clipboard.readText([type])`
30
24
31
-
*`type` String (optional) - Can be `selection` or `clipboard`. `selection` is only available on Linux.
25
+
*`type` String (optional) - Can be `selection` or `clipboard`; default is 'clipboard'. `selection` is only available on Linux.
32
26
33
27
Returns `String` - The content in the clipboard as plain text.
34
28
29
+
```js
30
+
const { clipboard } =require('electron')
31
+
32
+
clipboard.writeText('hello i am a bit of text!')
33
+
34
+
consttext=clipboard.readText()
35
+
console.log(text)
36
+
// hello i am a bit of text!'
37
+
```
38
+
35
39
### `clipboard.writeText(text[, type])`
36
40
37
41
*`text` String
38
-
*`type` String (optional) - Can be `selection` or `clipboard`. `selection` is only available on Linux.
42
+
*`type` String (optional) - Can be `selection` or `clipboard`; default is 'clipboard'. `selection` is only available on Linux.
39
43
40
44
Writes the `text` into the clipboard as plain text.
41
45
46
+
```js
47
+
const { clipboard } =require('electron')
48
+
49
+
consttext='hello i am a bit of text!'
50
+
clipboard.writeText(text)
51
+
```
52
+
42
53
### `clipboard.readHTML([type])`
43
54
44
-
*`type` String (optional) - Can be `selection` or `clipboard`. `selection` is only available on Linux.
55
+
*`type` String (optional) - Can be `selection` or `clipboard`; default is 'clipboard'. `selection` is only available on Linux.
45
56
46
57
Returns `String` - The content in the clipboard as markup.
47
58
59
+
```js
60
+
const { clipboard } =require('electron')
61
+
62
+
clipboard.writeHTML('<b>Hi</b>')
63
+
consthtml=clipboard.readHTML()
64
+
65
+
console.log(html)
66
+
// <meta charset='utf-8'><b>Hi</b>
67
+
```
68
+
48
69
### `clipboard.writeHTML(markup[, type])`
49
70
50
71
*`markup` String
51
-
*`type` String (optional) - Can be `selection` or `clipboard`. `selection` is only available on Linux.
72
+
*`type` String (optional) - Can be `selection` or `clipboard`; default is 'clipboard'. `selection` is only available on Linux.
52
73
53
74
Writes `markup` to the clipboard.
54
75
76
+
```js
77
+
const { clipboard } =require('electron')
78
+
79
+
clipboard.writeHTML('<b>Hi</b')
80
+
```
81
+
55
82
### `clipboard.readImage([type])`
56
83
57
-
*`type` String (optional) - Can be `selection` or `clipboard`. `selection` is only available on Linux.
84
+
*`type` String (optional) - Can be `selection` or `clipboard`; default is 'clipboard'. `selection` is only available on Linux.
58
85
59
86
Returns [`NativeImage`](native-image.md) - The image content in the clipboard.
60
87
61
88
### `clipboard.writeImage(image[, type])`
62
89
63
90
*`image`[NativeImage](native-image.md)
64
-
*`type` String (optional) - Can be `selection` or `clipboard`. `selection` is only available on Linux.
91
+
*`type` String (optional) - Can be `selection` or `clipboard`; default is 'clipboard'. `selection` is only available on Linux.
65
92
66
93
Writes `image` to the clipboard.
67
94
68
95
### `clipboard.readRTF([type])`
69
96
70
-
*`type` String (optional) - Can be `selection` or `clipboard`. `selection` is only available on Linux.
97
+
*`type` String (optional) - Can be `selection` or `clipboard`; default is 'clipboard'. `selection` is only available on Linux.
71
98
72
99
Returns `String` - The content in the clipboard as RTF.
73
100
101
+
```js
102
+
const { clipboard } =require('electron')
103
+
104
+
clipboard.writeRTF('{\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard\nThis is some {\\b bold} text.\\par\n}')
105
+
106
+
constrtf=clipboard.readRTF()
107
+
console.log(rtf)
108
+
// {\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard\nThis is some {\\b bold} text.\\par\n}
109
+
```
110
+
74
111
### `clipboard.writeRTF(text[, type])`
75
112
76
113
*`text` String
77
-
*`type` String (optional) - Can be `selection` or `clipboard`. `selection` is only available on Linux.
114
+
*`type` String (optional) - Can be `selection` or `clipboard`; default is 'clipboard'. `selection` is only available on Linux.
78
115
79
116
Writes the `text` into the clipboard in RTF.
80
117
118
+
```js
119
+
const { clipboard } =require('electron')
120
+
121
+
constrtf='{\\rtf1\\ansi{\\fonttbl\\f0\\fswiss Helvetica;}\\f0\\pard\nThis is some {\\b bold} text.\\par\n}'
122
+
clipboard.writeRTF(rtf)
123
+
```
124
+
81
125
### `clipboard.readBookmark()`_macOS__Windows_
82
126
83
127
Returns `Object`:
@@ -93,7 +137,7 @@ bookmark is unavailable.
93
137
94
138
*`title` String
95
139
*`url` String
96
-
*`type` String (optional) - Can be `selection` or `clipboard`. `selection` is only available on Linux.
140
+
*`type` String (optional) - Can be `selection` or `clipboard`; default is 'clipboard'. `selection` is only available on Linux.
97
141
98
142
Writes the `title` and `url` into the clipboard as a bookmark.
99
143
@@ -102,47 +146,60 @@ you can use `clipboard.write` to write both a bookmark and fallback text to the
102
146
clipboard.
103
147
104
148
```js
105
-
clipboard.write({
149
+
const { clipboard } =require('electron')
150
+
151
+
clipboard.writeBookmark({
106
152
text:'https://electronjs.org',
107
153
bookmark:'Electron Homepage'
108
154
})
109
155
```
110
156
111
157
### `clipboard.readFindText()`_macOS_
112
158
113
-
Returns `String` - The text on the find pasteboard. This method uses synchronous
114
-
IPC when called from the renderer process. The cached value is reread from the
115
-
find pasteboard whenever the application is activated.
159
+
Returns `String` - The text on the find pasteboard, which is the pasteboard that holds information about the current state of the active application’s find panel.
160
+
161
+
This method uses synchronous IPC when called from the renderer process.
162
+
The cached value is reread from the find pasteboard whenever the application is activated.
116
163
117
164
### `clipboard.writeFindText(text)`_macOS_
118
165
119
166
*`text` String
120
167
121
-
Writes the `text` into the find pasteboard as plain text. This method uses
122
-
synchronous IPC when called from the renderer process.
168
+
Writes the `text` into the find pasteboard (the pasteboard that holds information about the current state of the active application’s find panel) as plain text. This method uses synchronous IPC when called from the renderer process.
123
169
124
170
### `clipboard.clear([type])`
125
171
126
-
*`type` String (optional) - Can be `selection` or `clipboard`. `selection` is only available on Linux.
172
+
*`type` String (optional) - Can be `selection` or `clipboard`; default is 'clipboard'. `selection` is only available on Linux.
127
173
128
174
Clears the clipboard content.
129
175
130
176
### `clipboard.availableFormats([type])`
131
177
132
-
*`type` String (optional) - Can be `selection` or `clipboard`. `selection` is only available on Linux.
178
+
*`type` String (optional) - Can be `selection` or `clipboard`; default is 'clipboard'. `selection` is only available on Linux.
133
179
134
180
Returns `String[]` - An array of supported formats for the clipboard `type`.
135
181
182
+
```js
183
+
const { clipboard } =require('electron')
184
+
185
+
constformats=clipboard.availableFormats()
186
+
console.log(formats)
187
+
// [ 'text/plain', 'text/html' ]
188
+
```
189
+
136
190
### `clipboard.has(format[, type])`_Experimental_
137
191
138
192
*`format` String
139
-
*`type` String (optional) - Can be `selection` or `clipboard`. `selection` is only available on Linux.
193
+
*`type` String (optional) - Can be `selection` or `clipboard`; default is 'clipboard'. `selection` is only available on Linux.
140
194
141
195
Returns `Boolean` - Whether the clipboard supports the specified `format`.
142
196
143
-
```javascript
197
+
```js
144
198
const { clipboard } =require('electron')
145
-
console.log(clipboard.has('<p>selection</p>'))
199
+
200
+
consthasFormat=clipboard.has('<p>selection</p>')
201
+
console.log(hasFormat)
202
+
// 'true' or 'false
146
203
```
147
204
148
205
### `clipboard.read(format)`_Experimental_
@@ -157,26 +214,64 @@ Returns `String` - Reads `format` type from the clipboard.
157
214
158
215
Returns `Buffer` - Reads `format` type from the clipboard.
0 commit comments