/    Sign up×
Community /Pin to ProfileBookmark

Can Java copy text to clipboard?

I want to make a button that if clicked will copy a text string to the local clipboard. Basically doing the same thing as highlighting some text and pressing Ctrl-C

Can Javascript do this?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@shawjamesauthorMay 12.2003 — Cool, I got the copy to work... but I can only get it to copy to the clipboard text that is highlighted.

Can the copy command save a predefined text string to the clipboard?

I tried this:

document.execCommand("copy", "false", "test");

I wanted to try and save "text" to the clipboard everytime the function is called... but this didnt work.

Is there a different way to do this?
Copy linkTweet thisAlerts:
@BrainDonorJun 19.2003 — Is there a way to get the highlighted text to copy to the clipboard without the hyperlinks remaining active?

I have the copy and paste part working fine...

I have a "locked down" report that hides url, suppresses right clicks, etc. I want the user to be able to copy the page to the clipboard and paste the info into Excel without any of the hyperlinks remaining active. Is this possible?

Thanks!

Tom
×

Success!

Help @shawjames spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...