Advertisement
rAthus

JavaScript copier dans le presse-papier / copy to clipboard

Jul 7th, 2022
971
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).on('click','.lien-copie-presse-papier',function() {
  2.     var $btn = $(this);
  3.     var btntxt = $btn.html();
  4.     var txt2copy = location.href; // texte à copier
  5.     navigator.clipboard.writeText(txt2copy).then(
  6.         function() {
  7.             $btn.html("Copié !");
  8.         },
  9.         function() {
  10.             $btn.html("Erreur :(");
  11.         }
  12.     );
  13.     setTimeout(function() {
  14.         $btn.html(btntxt);
  15.     },2000);
  16. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement