0

I am using the following codeto export html table using javascript.

$(document).ready(function() {
    $("#btnExport").click(function(e) {
    e.preventDefault();

    //getting data from our table
    var data_type = 'data:application/vnd.ms-excel';
    var table_div = document.getElementById('history');
    var table_html = table_div.outerHTML.replace(/ /g, '%20');

    var a = document.createElement('a');
    document.body.appendChild(a);
    a.href = data_type + ', ' + table_html;
    a.download = 'exported_table_' + Math.floor((Math.random() * 9999999) + 1000000) + '.xls';
    a.click();
    e.preventDefault();});});

This works well on Chrome and Firefox. But in IE11 when I click the export button I am getting

The webpage cannot be displayed

Most likely cause: •Some content or files on this webpage require a program that you don't have installed.

PLEASE HELP

Hannoun Yassir
  • 20,583
  • 23
  • 77
  • 112
  • "_Some content or files on this webpage require a program that you don't have installed_" That's it, how could we help? – Teemu Jun 14 '17 at 11:47
  • add table id .. do not add div id here ->var table_div = document.getElementById('history'); – sac Jun 14 '17 at 11:51
  • I am already using the table ID :
    – Ajey Shetty Jun 14 '17 at 12:29
  • Maybe IE is more exquisite accepting excel MIME type, try other options. https://stackoverflow.com/questions/974079/setting-mime-type-for-excel-document – Bardo Jun 14 '17 at 12:47
  • I tried all the MIME. None worked for me in IE The webpage cannot be displayed Most likely cause: •Some content or files on this webpage require a program that you don't have installed. – Ajey Shetty Jun 14 '17 at 16:22
  • @Teemu I am just trying to pull the table in Excel. I am MS office installed. This script works in Mozilla and Crome. I am having issue only in IE. – Ajey Shetty Jun 14 '17 at 16:26
  • In windows 10 when i click export button in IE it tries to open an app in app store : Results for "data". Any idea why is it trying to open as "data" rather than XLS ? – Ajey Shetty Jun 15 '17 at 11:21

0 Answers0