xxxxxxxxxx
<!-- aks-ans -->
<button title="copy to clipboard" type="button" class="clipboard">Click me to copy Image Url</button>
var $temp = $("<input>");
var $url = 'http://localhost/';
$('.clipboard').hover(function() {
$(this).prop('title', 'Copy to clipboard');
});
$('.clipboard').on('click', function() {
$("body").append($temp);
$temp.val($url).select();
document.execCommand("copy");
$temp.remove();
$('.clipboard').prop('title', 'copied!');
})
xxxxxxxxxx
const copyToClipboard = (text) => navigator.clipboard.writeText(text);
copyToClipboard("Hello World");
xxxxxxxxxx
// Method 4 : Copying from input
<head>
<script>
function copyToCliBoard() {
var copyText = document.getElementById("myInput");
copyText.select();
copyText.setSelectionRange(0, 99999); /* For mobile devices */
document.execCommand("copy");
alert("Copied the text: " + copyText.value);
}
</script>
</head>
<body>
<input type="text" value="Some Context" id="myInput">
<button onclick="copyToCliBoard()">Copy text</button>
</body>
xxxxxxxxxx
const copyToClipboard = (text) =>
navigator.clipboard?.writeText && navigator.clipboard.writeText(text);
// Testing
copyToClipboard("Hello World!");
xxxxxxxxxx
methods: {
async copyURL(mytext) {
try {
await navigator.clipboard.writeText(mytext);
alert('Copied');
} catch($e) {
alert('Cannot copy');
}
}
}
xxxxxxxxxx
const copyToClipboard = (text) => navigator.clipboard.writeText(text);
copyToClipboard("Hello World");
xxxxxxxxxx
const CopyToClipboard = (whatToCopy) => navigator.clipboard.writeText(whatToCopy);
CopyToClipboard("Hello World!");
xxxxxxxxxx
const copyText = async (text: string) => await navigator.clipboard.writeText(text);
xxxxxxxxxx
function copyToClipboard(text) {
const el = document.createElement('textarea');
el.value = text;
document.body.appendChild(el);
el.select();
document.execCommand('copy');
document.body.removeChild(el);
}