0

I have the following script. It exports my data as .xls. I want a save dialog box to popup when this window opens. How can I accomplish this?

function ExporttoExcel() {
var sOption = "toolbar=yes,location=no,directories=yes,menubar=yes,";
sOption += "scrollbars=yes,width=750,height=600,left=100,top=25";

var sWinHTML = document.getElementById('contentstart').innerHTML;

var winprint = window.open("", "", sOption);
winprint.document.open();
winprint.document.write('<html><head>')

winprint.document.write('<meta http-equiv="Content-Type" content="application/vnd.ms-excel">')
winprint.document.write('<meta http-equiv="Content-disposition": attachment; filename="file.xls">')
winprint.document.write('</head><body>')

winprint.document.write(sWinHTML);
winprint.document.write('</body></html>');
winprint.document.close();
winprint.focus();
}
Brian Tompsett - 汤莱恩
  • 5,438
  • 68
  • 55
  • 126
Amen Ra
  • 2,777
  • 7
  • 42
  • 80

1 Answers1

1

You can find much inspiration on this SO thread : Export to csv in jQuery

And on this other thread too : How to download csv file using jquery?

Let us know what you have tried and if you had troubles.

Community
  • 1
  • 1
JMax
  • 25,301
  • 12
  • 66
  • 87