xxxxxxxxxx
// Copy to clipboard in node.js
const child_process = require('child_process')
// This uses an external application for clipboard access, so fill it in here
// Some options: pbcopy (macOS), xclip (Linux or anywhere with Xlib)
const COPY_APP = 'xclip'
function copy(data, encoding='utf8') {
const proc = child_process.spawn(COPY_APP)
proc.stdin.write(data, {encoding})
proc.stdin.end()
}
xxxxxxxxxx
function copy(value) {
navigator.clipboard.writeText(value);
};
copy("Hello World");
xxxxxxxxxx
// npm i clipboardy@2.3.0
const clipboardy = require("clipboardy");
// Copy
clipboardy.writeSync("something");
// Paste
clipboardy.readSync();
// something
xxxxxxxxxx
function copy() {
var copyText = document.querySelector("#input");
copyText.select();
document.execCommand("copy");
}
document.querySelector("#copy").addEventListener("click", copy);
xxxxxxxxxx
var el = x;
try {
el.select();
el.setSelectionRange(0, 99999); /* For mobile devices */
document.execCommand("copy");
} catch {
navigator.clipboard.writeText(el.innerText);
}
xxxxxxxxxx
function copyToClipboard(text) {
var copyText = document.createElement("textarea");
copyText.value = text;
document.body.appendChild(copyText);
copyText.select();
document.execCommand("copy");
document.body.removeChild(copyText);
}
// Usage example:
var textToCopy = "Hello, world!";
copyToClipboard(textToCopy);
xxxxxxxxxx
navigator.clipboard
.writeText("Text")
.then(() => console.log("Copied to clipboard"))
.catch((err) => console.log(err))
xxxxxxxxxx
function textToClipboard (text) {
var dummy = document.createElement("textarea");
document.body.appendChild(dummy);
dummy.value = text;
dummy.select();
document.execCommand("copy");
document.body.removeChild(dummy);
}
xxxxxxxxxx
var copyTextarea = document.getElementById("someTextAreaToCopy");
copyTextarea.select(); //select the text area
document.execCommand("copy"); //copy to clipboard
xxxxxxxxxx
$(document).ready(function(){
$("#ewefmwefmp").click(function(){
//alert()
var copyText = document.getElementById("myInput");
copyText.select();
copyText.setSelectionRange(0, 99999)
document.execCommand("copy");
alert("Copied the text: " + copyText.value);
});
});