Sharkey/src/client/app/common/scripts/copy-to-clipboard.ts

14 lines
320 B
TypeScript
Raw Normal View History

/**
* Clipboardに値をコピー(TODO: 文字列以外も対応)
*/
2017-03-18 12:05:11 +01:00
export default val => {
const form = document.createElement('textarea');
form.textContent = val;
document.body.appendChild(form);
form.select();
const result = document.execCommand('copy');
document.body.removeChild(form);
return result;
};