0

I'm trying add "data:application" type URI to an <a> tag href attribute. This is the code im using:

    var TestFuntion = (function() {
      var uri = 'data:application/vnd.xls;base64,'
        , template = '<table>{table}</table>'
        , base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))) }
        , format = function(s, c) { return s.replace(/{(\w+)}/g, function(m, p) { ; return c[p]; }) }
      return function(table, name) {
        if (!table.nodeType) table = document.getElementById(table)
        var ctx = {worksheet: 'test.xls' || 'Worksheet', table: table.innerHTML}
        var x = ( uri + base64(format(template, ctx))).toString();
        $('#testLink').attr('href',x)

      }

})()

I've tryed different ways using setAttribute and link.href reference to add the link but no success. This code example works in firefox and chrome.

I think the problem is that the href string that im trying to add is realy long like 10k+ charecters.

This is the link html:

<a id="testLink" download="Test.xls">
Mincho Minchev
  • 222
  • 3
  • 13
  • It seems that IE9 can accept 5120 according to this http://stackoverflow.com/questions/3721034/how-long-an-url-can-internet-explorer-9-take. Perhaps IE10 has the same issues. – Stuart Grant Nov 12 '13 at 08:17
  • ty for your comment. it will be realy annoying if this 5000 character limit is true.... is there any way to 'trick' the IE that my href is smallar then it is :? – Mincho Minchev Nov 12 '13 at 08:27
  • Why are you trying to do this? Why not a link to another file that outputs the same thing you try to include in your link? – putvande Nov 12 '13 at 09:21
  • @StuartGrant, I think that is for HTTP URLs. According to http://en.wikipedia.org/wiki/Data_URI_scheme#Web_browser_support IE 8 had a 32KB limit for Data URIs, and IE 9 should not have that any more. – CBroe Nov 12 '13 at 09:23

1 Answers1

0

All web browsers have limits for how long the URL can be. In addition, servers have these as well. Usually, an obscenely long URL indicates that you're trying to use a GET when you should be doing a POST.

If the server you're trying to connect to is your own (I assume it is), then you should use POST to send such huge data calls. If you absolutely need a GET, I'd look into reformatting your URL to a couple of GUIDs or something like that.

Nzall
  • 3,439
  • 5
  • 29
  • 59