html pass a string to clipboard

Solutions on MaxInterview for html pass a string to clipboard by the best coders in the world

showing results for - "html pass a string to clipboard"
Aitana
10 Oct 2017
1function copyToClipboard(text) {
2    var dummy = document.createElement("textarea");
3    // to avoid breaking orgain page when copying more words
4    // cant copy when adding below this code
5    // dummy.style.display = 'none'
6    document.body.appendChild(dummy);
7    //Be careful if you use texarea. setAttribute('value', value), which works with "input" does not work with "textarea". – Eduard
8    dummy.value = text;
9    dummy.select();
10    document.execCommand("copy");
11    document.body.removeChild(dummy);
12}
13copyToClipboard('hello world')
14copyToClipboard('hello\nworld')