Copy a string to the clipboard

tipjs,object

Copy a string to the clipboard. Only works as a result of user action (i.e. inside a click event listener).

const copyToClipboard = str => {
  const el = document.createElement('textarea');
  el.value = str;
  el.setAttribute('readonly', '');
  el.style.position = 'absolute';
  el.style.left = '-9999px';
  document.body.appendChild(el);
  const selected =
    document.getSelection().rangeCount > 0 ? document.getSelection().getRangeAt(0) : false;
  el.select();
  document.execCommand('copy');
  document.body.removeChild(el);
  if (selected) {
    document.getSelection().removeAllRanges();
    document.getSelection().addRange(selected);
  }
};
//Use
copyToClipboard('Lorem ipsum'); // 'Lorem ipsum' copied to clipboard.

Có thể bạn đã miss một số snippets code

using Typescript callback style error handling

Rest Operator for Objects

Now we can use rest on the properties of an Object. It allows us to explicitly extract certain named variables, and assign any uncalled variables into a catchall Object.

Lấy ngày hiện tại trong javascript

Lấy ngày hiện tại trong javascript

using async/await to catch errors

Hàm lày ngày trong tuần javascript

Hàm lày ngày trong tuần javascript