web/_javascript/utils/copy-link.js
2021-04-24 16:32:56 +08:00

18 lines
319 B
JavaScript

/*
* Copy current page url to clipboard.
*/
function copyLink(url) {
if (!url || 0 === url.length) {
url = window.location.href;
}
const $temp = $("<input>");
$("body").append($temp);
$temp.val(url).select();
document.execCommand("copy");
$temp.remove();
alert("Link copied successfully!");
}