如何在 Safari/Chrome 中从 javascript 打印 IFrame [英] How do I print an IFrame from javascript in Safari/Chrome

查看:28
本文介绍了如何在 Safari/Chrome 中从 javascript 打印 IFrame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮我通过 Safari/Chrome 中的 javascript 调用打印 IFrame 的内容吗.

Can someone please help me out with printing the contents of an IFrame via a javascript call in Safari/Chrome.

这在 Firefox 中有效:

This works in firefox:

$('#' + id)[0].focus();
$('#' + id)[0].contentWindow.print();

这在 IE 中有效:

window.frames[id].focus();
window.frames[id].print();

但我无法在 Safari/Chrome 中使用任何东西.

But I can't get anything to work in Safari/Chrome.

谢谢

安德鲁

推荐答案

在 iframe 中放置一个打印函数,并从父级调用它.

Put a print function in the iframe and call it from the parent.

iframe:

function printMe() {
  window.print()
}

父母:

document.frame1.printMe()

这篇关于如何在 Safari/Chrome 中从 javascript 打印 IFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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