Using prompt() I am generating some html to and need to know the maximum length that I can put in the popup.
I can't find anything in the spec about this, wondering if someone can help
Using prompt() I am generating some html to and need to know the maximum length that I can put in the popup.
I can't find anything in the spec about this, wondering if someone can help
As an example, Chrome (v41) limits the 2nd param for prompt() to 2000 characters.
If the value given is longer than that it truncates these 3 strings:
Here are some real world numbers in case anyone is interested. Please add more if you have any.
Using the following code in the browser console:
s = prompt("a", Array(SOME_NUMBER).join("0")); s.length;
karthick response was right, but you can check manually for the length of the input prompt this way, forcing the user to only enter less than a set amount of characters, or cancel:
The ECMAScript Programming Language Specification does not specify any maximum length. The maximum length with will be implementation-specific i.e, based on available memory.
This is beacuse there's no maximum length for prompt() in the spec. In order to limit the length, you'll need to check the length of the result after it's entered.
Try this :
As soon as you respond "Cancel", the navigator displays the last input length and the corresponding string. Cancel after 262144. Then test further. For very big length, refreshing the display may take a long time. I have no actual proof that the displayed string has the correct length. In the case of 262144 "+", I started tallying visually this string, but I dropped this game after 32 hours (just kidding).