Hye
I create a docx file with js inside an html iframe. It takes data from my site when button is clicked by:
$w('#html1').postMessage($w('#input1').value)
and creates the docx inside the html code, when clicking another button that I have created at the :
...
<body>
<button type="button" onclick="generate()">Download</button>
<script>
let receivedData="";
function generate() {
const doc = new docx.Document();
... // write receivedData to the doc
docx.Packer.toBlob(doc).then(blob => {
saveAs(blob, "MyFile.docx");
});
}
window.onmessage = (event) => {
if (event.data){
receivedData = event.data;
}
};
</script>
</body>
</html>
Now, the code below works FINE. But I don’t want 2 buttons. I want only my button at the site (which sends ‘post message’ to the html) and I want ‘window.onmessage’ create te doc and download it.
I’ve tried to call generate () inside window.onmessage after receiving the data, it doesn’t been called. I also tried to copy all the generate function code and paste it insdie window.onmessage, it doesn’t work too.
What am I missing?
Tnx