用jquery打印iframe内容 [英] printing iframe content with jquery

查看:113
本文介绍了用jquery打印iframe内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个iframe:

i have an iframe:

<iframe name="printarea" id="printarea" src="print.php" style="display: none;"></iframe>

我需要这个iframe有display:none;所以现在当有人点击通过php生成的链接时,它是不可见的

i need this iframe to have the style "display: none;" so it is invisible

echo '<a href="#" onclick="print_receipt('.$row['id'].'); return false;"><img src="images/icon-print.png" alt="" /></a>';

我希望它只是更改iframe SRC并打印iframe中的内容,不工作:

i want it to simply change the iframe SRC and print what is in the iframe, however my code is not working at all:

function print_receipt (id)
{
    $('#printarea').attr('src', 'print.php?id='+id);
    $('#printarea').focus();
    $('#printarea').print();
}

所以这是我想要的:
- 用户点击链接
- iframe内容根据他点击的链接而改变
- iframe内容打印

so this is what i want: - user clicks on link - iframe content changes based on the link he clicks - iframe content prints

推荐答案


  1. 您可能需要等待网页载入完毕

  2. print窗口对象的方法







   $('#printarea')
    .load(function(){this.contentWindow.print();$(this).unbind('load');})
     .attr('src', 'print.php?id='+id);

这篇关于用jquery打印iframe内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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