xxxxxxxxxx
const copyOnClipboard = (txt) => navigator.clipboard.writeText(txt)
xxxxxxxxxx
function copy() {
var copyText = document.querySelector("#input");
copyText.select();
document.execCommand("copy");
}
document.querySelector("#copy").addEventListener("click", copy);
xxxxxxxxxx
<html>
<input type="text" value="Hello world"(Can be of your choice) id="myInput"(id is the name of the text, you can change it later)
<button onclick="Hello()">Copy Text</button>
<script>
function Hello() {
var copyText = document.getElementById('myInput')
copyText.select();
document.execCommand('copy')
console.log('Copied Text')
}
</script>
xxxxxxxxxx
async function copyToClipboard(code) {
if (navigator.clipboard?.writeText) {
try {
await navigator.clipboard.writeText(code);
} catch(e) {
console.error('Error while copying code', e);
}
}
}
copyToClipboard("add string here...");
xxxxxxxxxx
<script>
function copyToClipboard(element) {
var $temp = $("<input>");
$("body").append($temp);
$temp.val($(element).text()).select();
document.execCommand("copy");
$temp.remove();
}
</script>
<p id="text">Hello</p>
<button onclick="copyToClipboard('#text')"></button>
xxxxxxxxxx
function copyToClipboard(){
var input = document.getElementById("short-url");
input.select();
navigator.clipboard.writeText(input.value);
}
xxxxxxxxxx
<script>
function copyReferralLink(link) {
var tempInput = document.createElement("input");
tempInput.style = "position: absolute; left: -1000px; top: -1000px";
tempInput.value = link;
document.body.appendChild(tempInput);
tempInput.select();
document.execCommand("copy");
document.body.removeChild(tempInput);
alert("Referral link copied to clipboard!");
}
</script>