19 lines
474 B
JavaScript
19 lines
474 B
JavaScript
|
|
$(document).on("click", "[data-behavior=clipboard]", function(e) {
|
||
|
|
e.preventDefault();
|
||
|
|
|
||
|
|
// Copy the value of the link's `href` attribute
|
||
|
|
var value = $(this).attr("href");
|
||
|
|
|
||
|
|
// Creates a temporary input field to copy from
|
||
|
|
var copyToClipboard = function(value) {
|
||
|
|
var $temp = $("<input>");
|
||
|
|
$("body").append($temp);
|
||
|
|
$temp.val(value).select();
|
||
|
|
document.execCommand("copy");
|
||
|
|
$temp.remove();
|
||
|
|
}
|
||
|
|
|
||
|
|
// Perform the copying
|
||
|
|
copyToClipboard(value);
|
||
|
|
});
|