Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to copy text of alert box

Tags:

javascript

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.
like image 423
Stack Over Avatar asked Jul 11 '13 10:07

Stack Over


People also ask

How do you copy a pop up box?

Was this reply helpful? Alt+PrintScreen will copy the active window (in this case the dialog box) to the Windows Clipboard. You can then paste it into a document.

How do I show messages in alert box?

Alert Box. Use the alert() function to display a message to the user that requires their attention. This alert box will have the OK button to close the alert box. The alert() function takes a paramter of any type e.g., string, number, boolean etc.


2 Answers

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?

like image 85
Eric Avatar answered Oct 11 '22 04:10

Eric


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.

like image 20
Sujeet malvi Avatar answered Oct 11 '22 06:10

Sujeet malvi