简体   繁体   中英

html link does not work href javascript parameter is too long

<a href="javascript:change('page_details_1','time,restime\n1387519869249,1196\n1387519906965,1368\n........')><img src="expand.jpg" alt="expand/collapse" id="page_details_1_image"></a>

in href i am calling a javascript function "change". The second parameter "\\n1387519869249,1196\\n1387519906965,1368\\n...." is a very long value about 5070 characters.but at 5052 characters the link works.

Is there a limit to number of characters that can pass through href? the data is used to generate trend graph . If there is such a limitation what would be the best way to pass such info to javascript function?

Try

<a href="javascript:void(0);" onclick="change('page_details_1','time,restime\n......'); return false;"><img src="expand.jpg" alt="expand/collapse" id="page_details_1_image"></a>

This way your URL isn't overly long.

The maximum limit of an href link is 2000: https://stackoverflow.com/a/417184/2413722 .

If it's just data that you are wanting to send, then add a data attribute and get JavaScript to read that value (this is simplified somewhat in jQuery).

Here's a great article on passing data with JSON. I'm using PHP and it's much easier than I thought :) http://betterexplained.com/articles/using-json-to-exchange-data/

Why not save the long term into a variable

value = "yes";
<a href="javascript:alert(value)">blubb</a>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM