web/_javascript/commons/copy-link.js
2021-04-20 04:22:28 +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!");
}