0

I have a <div> on my page that is constantly updated every 3 seconds. I'm using setInterval and AJAX to do this and update the <div>.

I've added a button that saves the current <div>'s data and writes it into a .html` file and then downloads it, but it's not working well across browsers.

In Chrome this works:

$("#save").click(function () {
    $('<a/>').attr({
          download: 'export.html', 
          href: "data:text/html," + $('#result').html() 
    })[0].click()
});

But it doesn't work in IE11, Firefox or Edge, it fails to do anything. In Safari it works but changes the current active page to export.html instead of downloading the export.html file.

Is there a way to do this that will work across browsers. Have the <div> output written to a html file and have it downloaded?

Thanks.

Penguin9
  • 481
  • 13
  • 23
Tom
  • 1,436
  • 24
  • 50

1 Answers1

0

I've updated my script to write the output shown in the DIV to a temp file on the server. The page then shows a download link and a backend download script gets the temp file and downloads it. This seems to work OK.

Tom
  • 1,436
  • 24
  • 50