1

Is there a way to send multiple lines of text to the clipboard using javascript?

IE, I want to send:

abc
def
ghi 

and not

abcdefghi

(and although right now i need to learn how to do it in Javascript, I would not mind hearing how it is done in other languages, like python)

EroSan
  • 339
  • 5
  • 13
  • Your question is an exact duplicate of "[Copy to clipboard in Javascript](http://stackoverflow.com/questions/453198/copy-to-clipboard-in-javascript)" you can check the answer there – Nadia Alramli May 28 '09 at 22:58
  • Yes it definitely possible, take a look at this answer of mine. https://stackoverflow.com/questions/46041831/copy-to-clipboard-with-break-line/50230647#50230647 – KeshavDulal May 08 '18 at 10:08

3 Answers3

2

did you try 'abc\r\ndef\r\nghi\r\n'

Russ Bradberry
  • 10,705
  • 17
  • 69
  • 85
  • it's all dependent on browser as well. some may need just \r, while others will need \r\n. your best bet is to go with a flash plugin that does it for you. look at the accepted comment for this question: http://stackoverflow.com/questions/400212/how-to-copy-to-clipboard-in-javascript – Russ Bradberry May 28 '09 at 23:28
1

Send it as one string with carriage return and line feed characters in it, as Russ suggested.

You replied to Russ that, "it does not work": what's the symptom of it not working?

If you're copying from the clipboard into HTML, note that whitespace (especially including carriage return and line feed characters) is not necessarily preserved by the HTML DOM when you insert it into the DOM.

ChrisW
  • 54,973
  • 13
  • 116
  • 224
0

I haven't tested it, but check out some of the jQuery plugins. http://plugins.jquery.com/taxonomy/term/657

Steven
  • 19,224
  • 47
  • 152
  • 257