Code is working fine in Chrome, unable to download excel in Firefox and IE

 

Below code is working fine in Chrome, unable to download excel in Firefox and IE:

<script language="text/javascript">

AJS.$(document).ready(function() {
console.log("Hello I am abc");
exportToExcel();
});
function exportToExcel(){

var uri = 'data&colon;application/vnd.ms-excel;base64,';
var template = '<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns="http://www.w3.org/TR/REC-html40"><head><!--[if gte mso 9]><xml><x:ExcelWorkbook><x:ExcelWorksheets><x:ExcelWorksheet><x:Name>{worksheet}</x:Name><x:WorksheetOptions><x:DisplayGridlines/></x:WorksheetOptions></x:ExcelWorksheet></x:ExcelWorksheets></x:ExcelWorkbook></xml><![endif]--></head><body><table>{table}</table></body></html>';
var base64 = function(s) {
return window.btoa(unescape(encodeURIComponent(s)))
};

var format = function(s, c) {
return s.replace(/{(\w+)}/g, function(m, p) {
return c[p];
})
};

var table1 = '<table>';

AJS.$('#customfieldmodule .property-list li').each(function() {
var temp = this.innerText;
console.log(temp);
var res1 = temp.substr(0,temp.indexOf(':'));
var res2 = temp.substr(temp.indexOf(':')+1);

table1 += '<td>';
table1 += res1;
table1 += '<br>';
table1 +=res2;
table1 += '</td>';

})
table1 += '</table>';

var issueKey = AJS.$("meta[name='ajs-issue-key']").attr("content");
var fileName = issueKey + ".xls";


var ctx = {
worksheet : issueKey,
table : table1
}


var link = document.createElement("a");
link.download = fileName;
link.href = uri + base64(format(template, ctx));
link.click();
}


</script>

 

Need Help!!

1 answer

Added the link element, 

document.body.appendChild(link);

Now able to download excel in firefox however still unable to download excel in IE.

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Fadoua M. Boualem
Published Monday in Trello

Using Trello to manage events

As a Jira power user, I was at first doubtful that Trello could benefit my workflow. Jira already uses boards (ones you can customize!), so why would I even need to use Trello?! In this post you will...

522 views 8 9
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you