0

I'm trying to achieve pretty basic function but still didn't succeed. How it should work - a user clicks a button and the iframe content is being exported as a html file. This is the code i have:

HTML:

<input type="button" value="Export" onclick="exportLog();">
<iframe id="log" src="https://colorfill.pl/email_signature.html">
</iframe>

JS:

function exportLog(){
    var elHtml = document.getElementById('log').innerText;
    var link = document.createElement('a');
    var mimeType = 'text/html';

    link.setAttribute('download', 'logFile');
    link.setAttribute('href', 'data:' + mimeType  +  ';charset=utf-8,' + encodeURIComponent(elHtml));
    link.click();
}

Fiddle: https://jsfiddle.net/hbvxkmnf/

I've also tried to change innerText into innerHTML, so far without success..

At the moment script downloads the file yet its totally empty.

Julia Galden
  • 381
  • 6
  • 22
  • `innerText` and `innerHTML` give you what is between ``, not what is on the other end of `src`. – Quentin May 04 '22 at 13:19

0 Answers0