admin管理员组文章数量:1425697
Trying to make a link that will copy some text, and what I was wondering (I have read some articles but they were for when people input things) if there was a way to just put any random text into the clipboard? I wanted to do this using JavaScript to do the actual copying and use PHP to get the actual data that I want to copy, I dont know that much JavaScript so keep that in mind, Thanks.
Trying to make a link that will copy some text, and what I was wondering (I have read some articles but they were for when people input things) if there was a way to just put any random text into the clipboard? I wanted to do this using JavaScript to do the actual copying and use PHP to get the actual data that I want to copy, I dont know that much JavaScript so keep that in mind, Thanks.
Share Improve this question asked Jan 19, 2016 at 14:21 Jack HalesJack Hales 1,6641 gold badge27 silver badges54 bronze badges 1- Nothing will beat Zero Clipboard: stackoverflow./questions/14432838/… – Hanky Panky Commented Jan 19, 2016 at 14:27
2 Answers
Reset to default 3This is a recurrent question and it is a lot of "solutions" but mostly you will end up using flash if you want full platform support.
If that is not the case, you can use libraries like clipboard.js, and there's a lot more out there, just look for them.
HTML
<div id="copy-text">Some Text</div>
<button onclick="copyToClipboard('#copy-text')" type="button" >Copy</button>
JS
function copyToClipboard(element) {
var $temp = $("<input>");
$("body").append($temp);
$temp.val($(element).text()).select();
document.execCommand("copy");
$temp.remove();
}
本文标签: Copy text to clipboard using JavaScriptPHPStack Overflow
版权声明:本文标题:Copy text to clipboard using JavaScriptPHP - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745420953a2657895.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论