0

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.

1

2 Answers 2

3

This 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.

Sign up to request clarification or add additional context in comments.

2 Comments

Flash itself doesn't exactly full platform support.
True, but sadly is the "most complete" solution we have so far
0

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();
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.