Welcome Guest Search | Active Topics | Sign In | Register

Inside IFRAME PRINT() is not working Options
mhoblit
Posted: Monday, May 11, 2020 9:36:34 AM
Rank: Member
Groups: Member

Joined: 3/25/2020
Posts: 10
Quote:

<html>
<head>
<script>
function PopulateAndPrintIFRAME() {
var iframe = document.createElement('iframe');
var html = '<body onload="window.print()">Foo</body>';
document.body.appendChild(iframe);
iframe.contentWindow.document.open();
iframe.contentWindow.document.write(html);
iframe.contentWindow.document.close();
}

</script>
</head>
<body onload="PopulateAndPrintIFRAME();">
TEST
</body>
</html>


When I open this in Chromium 77 I am able to see the print dialog and can print the IFRAME contents. I too have been researching this and see that someone has pointed to the chromium flag, mime-handler-view-in-cross-process-frame. However I am still able to print with this flag enabled or disabled in Chromium so I don't think that is the issue. What is causing EO to not execute the javascript "print()" command inside an IFRAME and is there a way to get it to work?

Background: Our application and website uses 2 embedded IFRAME services that have print commands that are no longer working. We do not have the ability to change any of the source code inside the IFRAME. This is a major disruption for our clients.
eo_support
Posted: Monday, May 11, 2020 4:56:26 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
Hi,

This is a known limitation of our implementation. The full printing message flow (BeforePrint -> Get print settings -> AfterPrint) is only implemented on top level frames. Thus it is not possible to directly print iframes. One workaround to this limitation is to automatically copy the contents of the iframe into a top level frame using WebView.JSInitCode property:

Code: C#
webView.JSInitCode = @"
if (window.self !== window.top)
{
    window.print = function()
    {
        var wnd = window.open("""", ""print"", """");
        wnd.document.open();
        wnd.document.write(document.documentElement.outerHTML);
        wnd.document.close();
    }
}
";


This code would override window.print for iframe only (by checking if (window.self !== window.top)) and perform the following task when window.print() is called on an iframe:

1. Use window.open to open a top level frame (For example, in TabbedBrowser sample application, this would open a new tab);
2. Copy the content of the iframe to the top level frame;

Once the copy finishes, whatever code that was in the original iframe that triggers window.print() will be automatically triggered again on the new top level frame. For example, in the code you posted it onload triggers window.print() on the iframe, thus it will be triggered again on the newly created top level frame. However since now it is a top level frame, window.print will sucessfully proceed and print the new frame.

Hope this helps. Please feel free to let us know if you still have any questions.

Thanks!

mhoblit
Posted: Tuesday, May 12, 2020 2:19:11 PM
Rank: Member
Groups: Member

Joined: 3/25/2020
Posts: 10
Thank you. That worked!
eo_support
Posted: Tuesday, May 12, 2020 5:58:04 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
Great!
KSystems
Posted: Thursday, September 10, 2020 4:39:18 PM
Rank: Advanced Member
Groups: Member

Joined: 1/15/2015
Posts: 48
Hello, I just wanted to inform you that we experienced this issue as well with EO 20.1.45 which is Chromium v77. Printing from iframe was reported by many to be an issue in Chrome browser as well with v77 and supposedly fixed in v80. I just updated to EO 20.2.63 which is v81 and the issue no longer exists. There is no need for this workaround proposed which is resource intensive.

Regards.
eo_support
Posted: Friday, September 11, 2020 10:58:28 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,217
Thanks for the update!


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.