最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

html - How to put newlines in JavaScript window.prompt? - Stack Overflow

programmeradmin0浏览0评论

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.

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.

Share Improve this question asked Sep 17, 2011 at 1:11 khekhe 211 silver badge2 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

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.

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?

发布评论

评论列表(0)

  1. 暂无评论