web/assets/js/_commons/copy-link.js
2020-09-17 19:20:50 +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;
}
var $temp = $("<input>");
$("body").append($temp);
$temp.val(url).select();
document.execCommand("copy");
$temp.remove();
alert("Link copied successfully!");
}