MS Edge - window.print() is not frame contextual in MS edge

风格不统一 提交于 2019-12-21 09:33:41

问题


Microsoft Edge is not handling window.print() consistently when compared with other browsers.

In most browsers calling window.print() from within an iframe on a page will only print the contents of that iframe. However in edge it will always print the whole document.

Was this intentional? Is there workaround?

Example on JSFiddle.

iframe.html

...
<body>
    <a href="#" onclick="window.print()">print iframe document</a>
</body>
...

index.html

...
<body>
    <a href="#" onclick="window.print()">print outer document</a>
    <iframe src="iframe.html"></iframe>
</body>
...

回答1:


This is a confirmed issue with microsoft, quote:

Posted by Microsoft on 7/29/2015 at 12:46 AM
We were able to confirm the issue, and will be working to resolve it in a future release

No workaround exists yet.




回答2:


We fount a magic solution:

parent.document.getElementsByName("pdfjs-frame")[0].contentWindow.document.execCommand("print", false, null);

...works in IE, EDGE, Chrome. The other was not tested yet.




回答3:


Its in IE too. You can fix it like this.

window.top.document.getElementById("iframe-id").contentWindow.focus();
window.top.document.getElementById("iframe-id").contentWindow.print();

It is tested. ;)



来源:https://stackoverflow.com/questions/31888223/ms-edge-window-print-is-not-frame-contextual-in-ms-edge

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!