krata/_javascript/utils/copy-link.js

19 lines
319 B
JavaScript
Raw Normal View History

/*
2020-08-19 06:26:45 +02:00
* Copy current page url to clipboard.
*/
2020-02-17 20:04:52 +01:00
function copyLink(url) {
2020-08-19 06:26:45 +02:00
if (!url || 0 === url.length) {
2020-09-17 13:20:50 +02:00
url = window.location.href;
2020-08-19 06:26:45 +02:00
}
2021-01-23 08:07:18 +01:00
const $temp = $("<input>");
$("body").append($temp);
$temp.val(url).select();
document.execCommand("copy");
$temp.remove();
alert("Link copied successfully!");
2020-08-19 06:26:45 +02:00
2020-09-17 13:20:50 +02:00
}