How to copy text of alert box

javascript

Solution

What you can do is to prompt the user with the text and ask them to copy it. As such:

prompt("Copy to clipboard: Ctrl+C, Enter", oArg.Document);

Because if you supply a text to the prompt it automatically gets selected. Does this suit you?

Problem

I write the path of a document into the alert box via using below code. ``` var oArg = new Object(); oArg.Document = $(t).attr("path") + str + "/" + $(t).attr("name"); alert(oArg.Document); ``` Assume that message is : "`documents/files/img/stack.jpg`" I only want to copy this text with a button. For Chrome Ctrl + C is ok for it but for IE, Ctrl + C copies everything at the alertbox. How can I copy only the message with using a button? Ctrl + C works like below: - Chrome - Works perfectly. - Internet Explorer - Works, but you get extra text. The caption and OK button text is also copied, along with a bunch of dashes. This is almost never what you want. - Firefox - Doesn't work at all You must select the text before you can copy it.

Original source