How to copy text of alert box

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.


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?


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)

Tags:

Javascript