July 2017
Intermediate to advanced
300 pages
5h 43m
English
We've learned how to pass text and graphics from our NW.js application to external programs, but how can we receive data from outside? As you can guess, it is accessible through the get method of nw.Clipboard. Text can be retrieved as follows:
const clip = nw.Clipboard.get(); console.log( clip.get( "text" ) );
When the graphic is put on the clipboard, we can get it with NW.js only as Base64-encoded content or as HTML. To see it in practice, we add a few methods to FileService:
./js/Service/File.js
//... hasImageInClipboard(){ const clip = nw.Clipboard.get(); return
clip.readAvailableTypes().indexOf( "png" ) !== -1; } pasteFromClipboard(){ const clip =
nw.Clipboard.get(); if ( this.hasImageInClipboard() ...Read now
Unlock full access