JavaScript copier dans le presse-papier / copy to clipboard
$(document).on('click','.lien-copie-presse-papier',function() {
var $btn = $(this);
var btntxt = $btn.html();
var txt2copy = location.href; // texte à copier
navigator.clipboard.writeText(txt2copy).then(
function() {
$btn.html("Copié !");
},
function() {
$btn.html("Erreur :(");
}
);
setTimeout(function() {
$btn.html(btntxt);
},2000);
});
Comments