从iframe打印pdf文件时出错。 [英] Error in printing pdf file from iframe.

查看:248
本文介绍了从iframe打印pdf文件时出错。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在按钮的点击事件中使用Iframe在网页中显示pdf文件。这是我写的代码

I have to show a pdf file in a webpage using Iframe,on the click event of a button.Here is the code I have written

//print pdf file
    $("#btnPrint").click(function () {      
        window.frames["printf"].focus();
        window.frames["printf"].print();
    });



这在Chrome中工作正常,在IE和FF中我得到以下错误


This works fine in Chrome,where as in IE and FF I am getting following errors

IE:-Error:SCRIPT65535: Invalid calling object




FF:-Error: Permission denied to access property 'print'



这里我没有使用任何插件显示Pdf。


Here I am not using any plugins to show the Pdf.

推荐答案

# btnPrint)。点击( function (){
window .frames [ printf]。focus();
window .frames [ printf< /跨度>]打印();
});
("#btnPrint").click(function () { window.frames["printf"].focus(); window.frames["printf"].print(); });



这在Chrome中运行良好,在IE和FF中我遇到以下错误


This works fine in Chrome,where as in IE and FF I am getting following errors

IE:-Error:SCRIPT65535: Invalid calling object




FF:-Error: Permission denied to access property 'print'



这里我没有使用任何插件来显示Pdf。


Here I am not using any plugins to show the Pdf.


我使用了一种解决方法,希望有人觉得它很有用:

函数WindowPrint(){

var iframe = document.frames? window.frames.frames [printFileFrame]:document.getElementById(printFileFrame);

var ifWin = iframe.contentWindow || iframe;

尝试{

ifWin.focus();

ifWin.print();

}

catch(e){

window.print(false);

//或当你收到IE9及以上版本的无效调用对象错误

//将浏览器设置为IE8兼容模式将起作用

}



返回false;



}
I use a workaround, hope someone find it useful:
function WindowPrint() {
var iframe = document.frames ? window.frames.frames["printFileFrame"] :document.getElementById("printFileFrame");
var ifWin = iframe.contentWindow || iframe;
try {
ifWin.focus();
ifWin.print();
}
catch(e) {
window.print(false);
//or when you get Invalid calling object error for IE9 and above
//set the browser into IE8 compatibility mode will work
}

return false;

}


有人在 Firefox [ ^ ] ,所以你必须等待。
Someone raised bug ticket on Firefox[^], so you have to wait.


这篇关于从iframe打印pdf文件时出错。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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