- 剪贴板
- 方法
- clipboard.readText([type])
- clipboard.writeText(text[, type])
- clipboard.readHTML([type])
- clipboard.writeHTML(markup[, type])
- clipboard.readImage([type])
- clipboard.writeImage(image[, type])
- clipboard.readRTF([type])
- clipboard.writeRTF(text[, type])
- clipboard.readBookmark() macOS Windows
- clipboard.writeBookmark(title, url[, type]) macOS Windows
- clipboard.readFindText() macOS
- clipboard.writeFindText(text) macOS
- clipboard.clear([type])
- clipboard.availableFormats([type])
- clipboard.has(format[, type]) 实验功能
- clipboard.read(format) 实验功能
- clipboard.readBuffer(format) 实验功能
- clipboard.writeBuffer(format, buffer[, type]) 实验功能
- clipboard.write(data[, type])
- 方法
剪贴板
在系统剪贴板上执行复制和粘贴操作。
进程: Main, Renderer
In the renderer process context it depends on the remote module on Linux, it is therefore not available when this module is disabled.
下面的示例演示如何将字符串写入剪贴板:
const { clipboard } = require('electron')clipboard.writeText('Example String')
在 X Window 系统上还有一个可选的剪贴板 。对其复制时需要传递selection 参数到每个函数:
const { clipboard } = require('electron')clipboard.writeText('Example String', 'selection')console.log(clipboard.readText('selection'))
方法
clipboard 对象具有以下方法:
注意: 被标记为实验性的 api 将来可能被删除。
clipboard.readText([type])
typeString(可选)
返回String- 剪贴板中的纯文本内容。
clipboard.writeText(text[, type])
textStringtypeString(可选)
将text作为纯文本写入剪贴板。
clipboard.readHTML([type])
typeString(可选)
返回String- 剪贴板中的HTML内容。
clipboard.writeHTML(markup[, type])
markupStringtypeString(可选)
将markup写入剪贴板。
clipboard.readImage([type])
typeString(可选)
返回NativeImage- 剪贴板中的图像内容。
clipboard.writeImage(image[, type])
imageNativeImagetypeString(可选)
将image写入剪贴板。
clipboard.readRTF([type])
typeString(可选)
返回String- 剪贴板中的RTF内容。
clipboard.writeRTF(text[, type])
textStringtypeString(可选)
向剪贴板中写入 RTF 格式的text.
clipboard.readBookmark() macOS Windows
返回 Object:
titleStringurlString
返回一个对象, 其中包含表示剪贴板中书签title和url。 当书签不可用时,title和url值将为空字符串。
clipboard.writeBookmark(title, url[, type]) macOS Windows
titleStringurlStringtypeString(可选)
将书签的title和url写入剪贴板。
注意:Windows上的大多数应用程序不支持粘贴书签,因此您可以使用 clipboard.write 将书签和后备文本写入剪贴板。
clipboard.write({text: 'https://electronjs.org',bookmark: 'Electron Homepage'})
clipboard.readFindText() macOS
返回 String- 查找粘贴板上的文本。 此方法在从渲染进程调用时使用同步 IPC。 每当激活应用程序时, 都会从查找粘贴板中重新读取缓存值。
clipboard.writeFindText(text) macOS
textString
将text作为纯文本写入查找粘贴板。此方法在从渲染进程调用时使用同步 IPC。
clipboard.clear([type])
typeString(可选)
清除剪贴板内容。
clipboard.availableFormats([type])
typeString(可选)
返回String []- 剪贴板type所支持的格式的数组。
clipboard.has(format[, type]) 实验功能
formatStringtypeString(可选)
返回Boolean, 剪贴板是否支持指定的format。
const { clipboard } = require('electron')console.log(clipboard.has('<p>selection</p>'))
clipboard.read(format) 实验功能
formatString
返回String- 从剪贴板中读取format类型的内容。
clipboard.readBuffer(format) 实验功能
formatString
返回Buffer- 从剪贴板中读取format类型的内容。
clipboard.writeBuffer(format, buffer[, type]) 实验功能
formatStringbufferBuffertypeString(可选)
将buffer作为format类型写入剪贴板。
clipboard.write(data[, type])
dataObjecttextString(可选)htmlString(可选)imageNativeImage (可选)rtfString (可选)bookmarkString (可选)- url 的标题text。
typeString(可选)
const { clipboard } = require('electron')clipboard.write({ text: 'test', html: '<b>test</b>' })
将 data 写入剪贴板。
