Please tell var dummyContent how to modify the text in the var dummyContent variable using JS or JQuery, so that it can be inserted into the "Multiline text" field via copy \ past code, while the text is added normally, tagged and saved. do not judge strictly, went through many examples, nothing fits. Code:

 function copy() { var dummyContent = 'Hello world'; var dummy = $('<input>').val(dummyContent).appendTo('body').select() document.execCommand('copy') } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="button" id="Copyitem" value="Копировать текст" onclick="copy();"> 

  • one
    Nothing is clear. Where is the "multiline text" field? What tags are we talking about? What is the problem in general and why is the existing code not comfortable? - Enikeyschik

1 answer 1

Use textarea for multiline input and the newline character '\n' inside the line:

 function copy() { var dummyContent = 'Hello world\nWorld hello'; var dummy = $('<textarea>') .val(dummyContent) .css("font-family", "Verdana") .css("font-size", "20px") .appendTo('body').select() document.execCommand('copy') } 
 <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <input type="button" id="Copyitem" value="Копировать текст" onclick="copy();"> 

  • Thanks for the example, '/ n' is useful, but not all ... there are options how to apply the font to this text and add URL links to the example? - Fox
  • Updated the code, added a change in the font and its size. You can’t insert a hyperlink into the input in any way; these objects are intended to make changes to the text. I advise you to look in the direction of HTML editors such as tinyMCE. - user218976
  • Thank you, but if I copy your text and paste it into Multiline text, the text size and fonts are not applied, only the "\ n" footnote is relevant. - Fox
  • @Melvin This is logical, since two code fragments are responsible for the change: .css("font-family", "Verdana") and .css("font-size", "20px") . They set textarea attributes and do not change later. - user218976
  • And I need the ability to insert text with ready-made fonts and markup in the column "Multiline text". - Fox