contentWindow.document.execCommand('print',false,null)在firefox中不起作用 [英] contentWindow.document.execCommand('print', false, null) not working in firefox

查看:1908
本文介绍了contentWindow.document.execCommand('print',false,null)在firefox中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为iframe实现一些打印功能,我正在使用下面的代码:

I am implementing some print function for iframe now , and i am using below code:

 $('#printBtn').click(function(){
     var iframe = document.getElementById('previewInfoBodyFrame');
     iframe.contentWindow.document.execCommand('print', false, null);
     return false;     
}); 

但我发现在firefox浏览器中,它不起作用,但对于IE,Chrome和safari,它工作正常。搜索了很多,但无法弄清楚这是怎么发生的。谁能提出一些想法?谢谢

but i found that in firefox browser, it's not working , but for IE,chrome and safari, it works fine. searched a lot but cannot figure out how this happening. anyone can give some ideas? Thanks

推荐答案

Firefox不支持execCommand('print')

https://developer.mozilla.org/en-US/docs/Web/API/document.execCommand

您可以使用 print()而不是函数。

You can use the print() function instead.

window.print() ;

https://developer.mozilla.org/en-US/docs/Web/API/Window.print

您可能需要阅读:
使用Javascript打印(部分)网页

希望这会有所帮助。

这篇关于contentWindow.document.execCommand('print',false,null)在firefox中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆