views:

214

answers:

4

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)

+1  A: 

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

Russ Bradberry
yeah, but it does not work...
EroSan
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
A: 

Your question is an exact duplicate of "Copy to clipboard in Javascript" you can check the answer there

Nadia Alramli
Thanks for pointing me to that. I'll look though it, but I dont think its the same question, tho. I know how to copy to clipboard, I just can't make it have a newline char or something so I pass multiple lines of text.
EroSan
A: 

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

Steven
+1  A: 

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