Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How many characters allowed in an alert box in JavaScript

Does anyone know what is the maximum number of characters you can display in an alert box?

I'm returning an error alert to the user with details for each of the errors and warnings but apparently the box just don't show up anymore when there is too much data. Here's some of my code:

<?php
    //Two arrays are created in php, one with the errors, one with the warnings.
?>

<script type="text/javascript">
    alert("<?php
         if(count($err) != 0){
             $errorfound = True;
             echo 'Error:\n\n';
             foreach($err as $message){
                 echo '\t' . $message . '\n';
             }
         }
         if(count($warn) != 0){
             echo '\n\nWarning:\n\n';
             foreach($warn as $mess){
                 echo '\t' . $mess . '\n';
             }
        }?>");
</script>

<?php
    //app continues if no error was found
?>

After investigation, my problem didn't come from the capacity of the alert box but was in fact that I needed to addslashes() to my messages (that's why I thought it was working with fewer values, but in fact I was just lucky because they weren't characters that needed to be escaped). I'll definitely change that alert box for something more appropriated, just wanted to say that there is no problem with the alert box.

like image 644
talnicolas Avatar asked Jul 28 '11 19:07

talnicolas


People also ask

How many buttons are there in a JavaScript alert box?

An alert box is used to inform/alert the user about an event. This type of popup box has only one button, named 'OK', and has no return value.

What is alert box in JavaScript?

Alert Box. An alert box is often used if you want to make sure information comes through to the user. When an alert box pops up, the user will have to click "OK" to proceed.

How many types of alerts are there in JavaScript?

In Javascript, popup boxes are used to display the message or notification to the user. There are three types of pop-up boxes in JavaScript namely Alert Box, Confirm Box and Prompt Box. Alert Box: It is used when a warning message is needed to be produced.


1 Answers

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.

like image 179
dwmcc Avatar answered Sep 30 '22 18:09

dwmcc