SoFunction
Updated on 2025-04-05

Is there a length limit for js parameters? It is found that it cannot exceed 2083 characters

A normal javascript function with only one entry parameter
Copy the codeThe code is as follows:

function test(info)
<img none';="" ('_20_37_open_text').="none" ;="" ('_20_37_closed_image').="inline" ('_20_37_closed_text').="inline" ;"="" alt="" src="/syntaxhighlighting/OutliningIndicators/" align="top" style="border: 0px; max-width: 100%; ">{
alert(info);
}

The page is generated using aspx code. The entry parameter of the call test function may be a very long string. At the same time, many tags shown below are constructed based on a data set on the page.
Copy the codeThe code is as follows:

<a href="javascript:test('ssssss...it's long here..ssssss')">test</a>

After the page is generated, some links can be clicked, while some cannot be clicked. I roughly processed the value of the entry parameter with substring and found that it cannot exceed 2083 characters. Is there a length limit for the function parameters of js? Never heard of it. No relevant statement was found.

Try to replace the <a> tag with <button> and then call this js function in the clik event. The parameters are passed to all lengths and found that there is no error...

This sudden realization turned out to be caused by <a href>. <a href> is to use get to pass parameters, and the url has a length limit of 2k. Even in this case, the js function cannot be exceeded.