Skip to content Skip to sidebar Skip to footer

How To Copy Text Of Alert Box

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.Docum

Solution 1:

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?

Solution 2:

When ever the alert message box appears with the text message , just press CTRL+ C and your message will be copied, then you can paste it anywhere you want , no need to write it or using any other method to get the text.

Solution 3:

I've found that, in Chrome at least, the alert box text is in fact selectable -- when the text does not contain any line-breaks (ie. "\n").

I don't know why this is the case, but I've had to use this trick before for quick selection prompts. (you could also use prompt("please press ctrl+c to copy the text below", "text to copy"), but that usually looks worse)

Post a Comment for "How To Copy Text Of Alert Box"