?>

Comment copier du texte javascript dans le presse papier?

Comment copier du texte javascript dans le presse papier?

Pour copier un texte dans le presse-papier js, vous pouvez coller ce texte dans une entrée, qui doit être visible et non dans un div tordu, sélectionnez-le et utilisez la fonction intégrée js document.execCommand ("copy");

Html

<i class="fas fa-copy sx-copy" style="cursor: pointer;" data-toggle="tooltip" title="Скопировать ссылку"></i> <input id="cont" type="text" value="Любой ваш текст" style="position: absolute; left: -20000px;"/> 

Veuillez noter que l'entrée est visible mais que, pour ne pas être visible, elle utilise le positionnement absolu -20000px

Js

$(".sx-copy").on("click", function() { var input = document.getElementById("cont"); // Select the input node's contents input.select(); // Copy it to the clipboard _.delay(function() { try { // Теперь, когда мы выбрали текст ссылки, выполним команду копирования var successful = document.execCommand("copy"); var msg = successful ? 'successful' : 'unsuccessful'; sx.notify.success("Ссылка скопирована"); } catch(err) { throw err; sx.notify.error('Oops, unable to copy'); } }, 300); }); 

Tous les commentaires (0)
Sans commentaires