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">