30

Past versions of Internet Explorer croaked on web addresses longer than 2,083 characters (see http://support.microsoft.com/kb/208427). Meanwhile, Firefox, Opera, and Safari can handle at least 80,000.

Version 9 brings many improvements. Is URL length is one of them?

5
  • 2
    Belongs on superuser.com
    – dogbane
    Sep 15, 2010 at 19:23
  • 20
    @fahd no it doesn't - it's essential info for web developers
    – Pekka
    Sep 15, 2010 at 19:27
  • 1
    Length is not all that matters... it's about how you can use it - servers may have a significantly smaller limit to protect against some exploits and unauthorized intrusion.
    – Arc
    Sep 15, 2010 at 19:28
  • 1
    @Archimedix absolutely. I'm not saying it's a good thing to go too far beyond a few kilobytes in URL length. But knowing where IE9's limits are is a legitimate thing to ask.
    – Pekka
    Sep 15, 2010 at 19:40
  • 1
    IE9 has various limits (address bar, A HREF, Location header, etc). URLs under 2083 characters will work everywhere. Longer URLs can be resolved and navigated, but cause assorted problems (e.g. results will not be cached) and should be avoided if at all possible.
    – EricLaw
    Jul 15, 2013 at 21:22

3 Answers 3

18

Not the most precise answer, but it looks like 2083 characters in the address bar and 5165 characters when following a link.

(Not official in any way, just plugged a URL with 41,000 chars into a test HTM file and used Javascript to query the URL length.)

Update:

To reproduce the test, create an HTML file with an anchor element whose HREF attribute is 6000 characters long. Open the file in your browser and click the link. Then pop open the console and check window.location.href.length.

Following this procedure in IE9 today, it reports the length as 5165 characters. If I load the same URL manually through the address bar, it reports 2083 characters.

For what it's worth, IE seems to truncate the URL before sending the request. If I put a URL of 24,000 characters in the anchor's HREF attribute, IE will follow the link but the resulting page reports a url length of 5165 characters. Following the same link in Chrome results in a HTTP 414 response from my test server.

1
  • I haven't seen any documentation on the 5150 cap in links before, but it would definitely explain some issues I'm having since URLs in my links > 2083 chars are working, yet fail when put in the address bar. Is this just empirical--did you just try larger URLs until they failed?
    – Chet
    Aug 7, 2012 at 19:50
10

I get 5120 characters in a url for internet explorer 9.

By no means a definitive test but the following demonstrates a quick check for url length of a href attribute in an anchor tag.

<html>
    <head>
        <script type="text/javascript">
            function init() {
                var anchor = document.getElementById('anc');
                var valid = true;
                var url = 'http://google.com/?search=';
                var count = url.length;

                while(valid) {
                    url = url + '1';
                    anchor.href = url;
                    count++;
                    valid = anchor.href == url;

                    if(count > 100000) {
                        alert('Test reached 100,000, stopping...');
                        valid = false;
                    }
                }
                alert('Complete, count = ' + count);
            }
        </script>
    </head>
    <body onload="init()">
        <a id="anc" href="http://google.com/">Test</a>
    </body>
</html>
1
  • 2
    Sounds plausible - the IE9 release notes included the following: "IE9 features improved support for “Bookmarklets”—URL length limits were relaxed." No specifics unfortunately. RE your test - the max length of in-page HREFs is not necessarily the same as the max length of URL that the browser will transmit (e.g., via address bar). Need to verify by submitting and checking server logs to see at what point truncation occurs (or an error?). Anyone have definitive info for IE9?
    – psdie
    Apr 7, 2012 at 7:55
1

I wrote this test that keeps on adding 'a' to parameter until browser fails

C# part:

[AcceptVerbs(HttpVerbs.Get)]
public ActionResult ParamTest(string x)
{
    ViewBag.TestLength = 0;
    if (!string.IsNullOrEmpty(x))
    {
        System.IO.File.WriteAllLines("c:/result.txt", 
                       new[] {Request.UserAgent, x.Length.ToString()});
        ViewBag.TestLength = x.Length + 1;
    }

    return View();
}

View:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

<script type="text/javascript">
    $(function() {
        var text = "a";
        for (var i = 0; i < parseInt(@ViewBag.TestLength)-1; i++) {
            text += "a";
        }

        document.location.href = "http://localhost:50766/Home/ParamTest?x=" + text;
    });
</script>

I added additional limits to IISExpress applicationhost.config and web.config setting maxQueryStringLength="32768".

also Added to config

<headerLimits>
    <add header="Content-type" sizeLimit="32768" />
</headerLimits>

which didn't help at all, Finally decided to use fiddler to remove referer from header.

static function OnBeforeRequest(oSession: Session) {
if (oSession.url.Contains("localhost:50766")) {
        oSession.RequestHeaders.Remove("Referer");
        }

Which did nicely.

On IE9 I got

Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)
4043

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.