web/assets/js/_commons/copy-link.js

24 lines
425 B
JavaScript
Raw Normal View History

/*
2020-08-19 07:26:45 +03:00
* Copy current page url to clipboard.
* v2.1
* https://github.com/cotes2020/jekyll-theme-chirpy
* © 2020 Cotes Chung
* MIT License
*/
2020-02-17 22:04:52 +03:00
function copyLink(url) {
2020-08-19 07:26:45 +03:00
if (!url || 0 === url.length) {
return;
}
2020-02-17 22:04:52 +03:00
url = window.location.href;
var $temp = $("<input>");
$("body").append($temp);
$temp.val(url).select();
document.execCommand("copy");
$temp.remove();
alert("Link copied successfully!");
2020-08-19 07:26:45 +03:00
}