To copy any text into js clipboard, you can paste this text into input, which must be visible and not in a twisted div, select it and use the built-in js document.exe function ("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;"/>
Please note that the input is visible but in order to be not visible it uses absolute positioning -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); });
- Семенов Александр
- /
- Apr 7, 2019
- /
- 0
- /
- 11429
Popular
Happy New Year and Merry Christmas!
- Dec 30, 2022
SaleEvent Markup
- Nov 23, 2022
We continue to improve the tools of the online store
- Oct 27, 2022
All Comments (0)