web/_javascript/utils/copy-link.js

23 lines
406 B
JavaScript
Raw Normal View History

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