web/assets/js/_commons/copy-link.js
2021-01-25 06:43:02 +08:00

22 lines
417 B
JavaScript

/*
* Copy current page url to clipboard.
* v2.1
* https://github.com/cotes2020/jekyll-theme-chirpy
* © 2020 Cotes Chung
* MIT License
*/
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!");
}