2

I want to put selected text a user can select in a prompt.

function copyToClipboard (text) {
    window.prompt ("Copy to clipboard: Ctrl+C, Enter", text);
}

The problem with this is that the text may have newlines. In that case, I only see the first line of the text. Is there anyway I can insert newlines or maybe have a custom prompt that allows this? Thanks.

khe
  • 21
  • 1
  • 2

2 Answers2

5

The new line thing --> \n

So what you will do is simply type:

prompt("Hello world,\nA newline!", [default text]);

And about the custom prompt thing, there is no such thing in W3C. However, it does have a similar thing called the Modal Dialog, which is just a new window containing a website in it.

Peter H
  • 5,009
  • 2
  • 23
  • 42
Derek 朕會功夫
  • 84,678
  • 41
  • 166
  • 228
2

window.prompt won't be capable of doing that, perhaps you should look at a more convenient (and better) approach:

How do I copy to the clipboard in JavaScript?

Community
  • 1
  • 1
basicxman
  • 2,077
  • 14
  • 21