简体   繁体   English

MS Edge - window.print()在MS边缘不是帧上下文

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

Microsoft Edge is not handling window.print() consistently when compared with other browsers. 与其他浏览器相比,Microsoft Edge不会始终如一地处理window.print()。

In most browsers calling window.print() from within an iframe on a page will only print the contents of that iframe. 在大多数浏览器中,从页面上的iframe中调用window.print()只会打印该iframe的内容。 However in edge it will always print the whole document. 但是在边缘,它将始终打印整个文档。

Was this intentional? 这是故意的吗? Is there workaround? 有解决方法吗?

Example on JSFiddle . 关于JSFiddle的例子

iframe.html Iframe.html的

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

index.html 的index.html

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

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. 还没有解决方法。

We fount a magic solution: 我们有一个神奇的解决方案:

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

...works in IE, EDGE, Chrome. ...适用于IE,EDGE,Chrome。 The other was not tested yet. 另一个尚未测试。

Its in IE too. 它也在IE中。 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. 经过测试。 ;) ;)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM