How many characters allowed in an alert box in JavaScript

Personally I despise popup alerts. You might consider using a message box built into the page that can hold an indefinite amount of content, and can be "flashed" on the screen for a few seconds on error.

You can optionally disable the entire page and make the message an overlay. Prototype or jQuery would make quick work of either task.

If you want to see an example of disabling the page, this article uses a progress indicator that could easily be swapped for a message. http://edwardawebb.com/web-development/cakephp/disable-page-show-translucent-progress-bar


Test code :

<html>
  <head>
    <script>
function test ()
{
  let i;
  let nums = "";
  for ( i = 0; i <= 9999; i++ ) // ◄█■ GENERATE STRING WITH 48890 CHARS.
     nums += i.toString() + " ";
  alert( nums ); // ◄█■ DISPLAY STRING IN ALERT.
}
    </script>
  </head>
  <body onload="test()">
  </body>
</html>

When alert is displayed, copy text, paste it in Microsoft Word, and use "count characters" tool, next image is text from Firefox 84.0.2, 10000 chars :

enter image description here

Next image is from Chrome 88.0.4324.104, its alert can only hold 1833 chars :

enter image description here


Let's see if I can actually answer your question:

There is no 'maximum' alert size in Javascript. It varies from browser to browser. You'd probably be best staying under 1000 characters though, as many browsers seem to begin to truncate after 999.