Desperately trying to print an iFrame in a context of cross domain (cross origin)

52 Views Asked by At

On our company Microsoft 365 platform I have a spreadsheet (in Sharepoint) that is used as a specialized calculator, with instructions and example.

Using an iFrame, this spreadsheet is used in our web site, but I'm unable to print it, possibly for reason of cross origin, but I'm not knowledgeable enough to be sure.The only thing sure is that it doesn't even open the print preview page.

There are 2 scenarios below. None is printing, and the second one doesn't even display the spreadsheet.Those are only 2 of a lot lot of tries...

<button onclick="document.getElementById('iframe').contentWindow.print()">Print</button>

    <iframe id="proxy" width="402" height="346" frameborder="0" scrolling="no" src="https://bitumequebecorg-my.sharepoint.com/:x:/g/personal/tic_bitume_quebec1/EYi9K47PNs1HrtL76chXWm8Bqt6IObi7_r1cIIA_GVs9zw?e=o3xNTw&action=embedview&wdAllowInteractivity=True" allow-popups></iframe>

  <script>
    var proxy = document.getElementById('proxy');
    var iframe = document.createElement('iframe');
    iframe.src = '/proxy?url=' + encodeURIComponent(proxy.src);
    proxy.contentDocument.body.appendChild(iframe);
  </script>

---

<button onclick="printIframe()">Print iframe</button>

<iframe id="proxy" width="402" height="346" frameborder="0" scrolling="no">
  <iframe id="cross-domain-iframe" width="402" height="346" frameborder="0" scrolling="no"src="https://bitumequebecorg-my.sharepoint.com/:x:/g/personal/tic_bitume_quebec1/EYi9K47PNs1HrtL76chXWm8Bqt6IObi7_r1cIIA_GVs9zw?e=o3xNTw&action=embedview&wdAllowInteractivity=True"></iframe>
</iframe>

<script>
  function printIframe() {
    var proxy = document.getElementById('proxy');
    var iframe = proxy.contentWindow.document.getElementById('cross-domain-iframe');
    iframe.contentWindow.print();
  }
</script>

You can see the result here: https://guignoleerivesud.org/atest-print-with-cross-domain/

I would really appreciate if someone can help me with that issue.

Thanks,

Gaston

PS: I think that I reviewed all related questions on Stack Overflow, but obviously I missed something.

0

There are 0 best solutions below