js copy string to clipboard
// Since Async Clipboard API is not supported for all browser!
function copyTextToClipboard(text) {
var textArea = document.createElement("textarea");
textArea.value = text
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
var successful = document.execCommand('copy');
var msg = successful ? 'successful' : 'unsuccessful';
console.log('Copying text command was ' + msg);
} catch (err) {
console.log('Oops, unable to copy');
}
document.body.removeChild(textArea);
}function copyToClipboard(text) {
var input = document.body.appendChild(document.createElement("input"));
input.value = text;
input.focus();
input.select();
document.execCommand('copy');
input.parentNode.removeChild(input);
}const el = document.createElement('textarea');
el.value = str; //str is your string to copy
document.body.appendChild(el);
el.select();
document.execCommand('copy'); // Copy command
document.body.removeChild(el);var copyTextarea = document.getElementById("someTextAreaToCopy");
copyTextarea.select(); //select the text area
document.execCommand("copy"); //copy to clipboard
Also in JavaScript:
- $.get jquery return value
- javascript vererbung Klasse extends super constructor
- laravel pass collection to javascript
- js string to object
- python http request post json example
- google app script column to array indexOf
- Error: There was an unhandled exception on the current circuit, so this circuit will be terminated. For more details turn on detailed exceptions by setting 'DetailedErrors: true' in 'appSettings.Development.json' or set 'CircuitOptions.DetailedErrors'.
- how to get element by class name javascript
- javascript lowercase
- generate random alphanumeric string javascript
- jquery filter data
- Pass unknown number of arguments into javascript function
- react native elements
- array concat in javascript
- how to reload webview in react native
- javascript detect touch screen device
- using multiple http verbs on express path request
- ajax send multiple data to php
- javascript string error
- use promise in angular 8
- transformorigin gsap
- what is download api javascript
- float force loopback
- new instance of object javascript