The Clipboard API – accessing the system clipboard
NW.js' Clipboard API lets you read and write plain text from the system clipboard. There are three main methods to access the content of the clipboard. Clipboard.set(data)
enables you to copy some text data into the clipboard, the Clipboard.get()
method allows you to retrieve that data, and Clipboard.clear()
allows you to clear it up. The following is a simple example:
var gui = require('nw.gui'), clipboard = gui.Clipboard.get(); // Copy clipboard.set('I love NW.js :)'); // Paste var data = clipboard.get('text'); // Clear clipboard.clear();
Note
The NW.js Clipboard API is still pretty young. At the moment, you can only access plain text and only from the system clipboard. The selection clipboard in X11 is not supported.
Tip
In order to do cut, copy, and paste, you can rely on document.execCommand('cut')
, document.execCommand('copy')
and document.execCommand('paste')
.