O'Reilly logo

Cross-platform Desktop Application Development: Electron, Node, NW.js, and React by Dmitry Sheiko

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Receiving text and graphics

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() ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required