Multiple lines of text to clipboard

2019-06-02 22:32发布

问题:

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:

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.



回答2:

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



回答3:

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