0

I have several html A tag generated programmatically in ASP.NET with a JavaScript function taking long parameter in href. One of those has over 20K characters when it get assigned in backend, but I am seeing the actual link has only 5239 characters on the browser side and the JavaScript function does not have closing. So the link never works. I am thinking about workarounds for this implementation since it's not a good idea to put this much amount of data in links, but now I'm just curious about cause of the issue.

Examples of the code assigning values to the link:

HtmlAnchor.HRef = "javascript:doSomething('Import','" + strHeader_LineIds + "');"

In this case the variable strHeader_LineIds carries a string over 20k characters.

Example of what I'm actually seeing in client side:

<a id=anchor1 class=class1 href="javascript:doSomething('Import', 'blahblahblahblah....">Link Text</a>

Please note the javascript function has no closing here. But when I'm debugging in backend I do see the closing of the function.

I guess this issue may have something to do with the browser's URL limit? I am using IE and I learned IE has a maximum URL length limit as 2,083 characters from Here. But how can the link show up with 5,239 characters?

wctiger
  • 921
  • 12
  • 22
  • Does changing to `HtmlAnchor.OnClientClick = "doSomething('Import', '" + strHeader_LineIds + "');";` fix anything? – Greg Burghardt Oct 29 '15 at 16:28
  • 1
    Possible duplicate of [html link does not work href javascript parameter is too long](http://stackoverflow.com/questions/20733616/html-link-does-not-work-href-javascript-parameter-is-too-long) – Greg Burghardt Oct 29 '15 at 16:33
  • @GregBurghardt Thanks. Answer in that question does make sense to me, but I am still wondering about cause of this issue since I got a weird number in the link's length. – wctiger Oct 29 '15 at 16:46

2 Answers2

0

I've had a similar issue with javascript like dynamic functions created in code and then called. I found that I had to play with swapping out single quotes in the javascript function with double quotes or escaping the quotes.

Then again just reading your post could be a limit issue.

Have you tried assigning the long to an element in the background and then referencing that as part of the javacript. I know IE gets funny with spaces in passed in parameters.

0

I think found an answer to the issue though. According to This Article:

JavaScript URIs The JavaScript protocol is used for bookmarklets (aka favlets), a lightweight form of extensibility that permits a user to click a button and run some stored JavaScript on the currently loaded page. In IE9, the team did some work to relax the length limit (from ~260 characters, if I recall correctly) to something significantly larger (~5kb, if I recall correctly).

So I just hit the ~5kb limit.

wctiger
  • 921
  • 12
  • 22