Reading and writing to a user’s board can be both useful and dangerous. Used properly and it is a huge convenience for the user; In dubious use and the user may suffer catastrophic consequences. Imagine a wrong account number or wrong wallet address copied – err! This is why programmatic copying and pasting should be protected, and why the JavaScript board API requires explicit user permission to allow the site to use it.
To call the user’s board, you use readText
method:
const clipboardData = await navigator.clipboard.readText();
To write to the user’s clipboard, you use writeText
method:
await navigator.clipboard.writeText('');
Obviously the API is very easy to use – each method returns a promise so you can use it async
/await
or then
Repeat calls. The hard part is finding the balance of when to use each of them. Unnecessary readings will feel intrusive, and unnecessary writing will significantly melt the user’s trust.
When might you want to write to the board? Maybe after the user pastes an initial phrase, password or credit card number in the form fields with the same name.
Sure you can use the number of libraries available to simulate this API, but know that an official API does exist. And as always, I teach you how to use it – it’s up to you to make sure it’s the right time and tool for the job!
Create namespace classes with MooTools
MooTools has always suffered a bit of regret for not using built-in and standardized namespace-based JavaScript classes like the Dojo toolkit does. Many developers create their own classes as globals, which is usually screaming. I mostly disagree with this position, but each has his own. At every event …
CSS animations between media queries
CSS animations are right up there with sliced bread. CSS animations are efficient because they can be accelerated with hardware, they do not require JavaScript overhead, and they consist of very little CSS code. We often add CSS transformations to elements using CSS during …
MooTools 1.2 OpenLinks plugin
I often incorporate tools on my clients’ sites that allow them some control over the content on their site. When I do this, I offer my clients some tips to help them keep their website in good condition. One of the tips …
Source