Copy to clipboard with break line

后端 未结 4 1387
你的背包
你的背包 2020-12-01 12:53

I want to copy a text to clipboard but in a new line.

Problem:

If you click the button in the snippet and paste in the notepad this is what

4条回答
  •  天涯浪人
    2020-12-01 13:10

    Your code is probably working well, but Notepad can't handle Unix' \n newlines, it only can handle \r\n and this is why you don't see them.

    Please download a more advanced editor (like Notepad++, https://notepad-plus-plus.org) and try pasting it there. And not only that, but it has a lot of other very cool features like syntax highlighting, macros and plugins so it's worth using it for more purposes than that.

    If you want to make the newlines work in MS apps, you need to replace the newlines just before you copy by using this line:

    $temp = $temp.replace(/\n/g, "\r\n");
    

    For printing in HTML you would need to replace \n with
    , like this:

    $temp = $temp.replace(/\n/g, "
    ");

提交回复
热议问题