Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alert box text copy issue with Chrome

Tags:

javascript

Hi I would like to know the way with which I can straight away copy the text in alert box, it is allowing me to copy the text in IE, Safari but not in latest chrome version. Any idea how to do the same.

Thanks

like image 857
pranaysampat Avatar asked Jun 29 '17 14:06

pranaysampat


1 Answers

I've had this problem, as I've wanted to copy text in an alert to a translator since it was in a language I didn't read.

What I ended up doing was:

While on the page that causes the alert to appear, open Chrome's developer tools by typing (F12) or (CTRL SHIFT I) or Menu-> More Tools -> Developer tools.

Go to the developer tools console pane and, at the text entry prompt starting with >, type:

alert = ( () => {
  const oldAlert = alert;
  var inAlert = false;
  return (x) => {
    if (!inAlert) {
      console.log(x);
      inAlert = true;
      return oldAlert(x)
      inAlert=false;
    };
  }
} )()

That command supplements the alert functionality so that any alert message also gets written to the debug console, where it's easy to copy. Now, do whatever you did that causes the alert to appear and dismiss it. When you go look at that console window, you should see that it has printed the text you wanted to copy. You can copy it from there.

like image 122
Stuart Schechter Avatar answered Oct 06 '22 00:10

Stuart Schechter