带有pdf的ie11中的javascript框架导航 [英] javascript frame navigation in ie11 with a pdf

查看:90
本文介绍了带有pdf的ie11中的javascript框架导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的网页,其中一帧显示pdf,另一个显示菜单栏.

I have a simple web page where 1 frame displays a pdf and another a menu bar.

<iframe src="bar.html" name="menu"  ></iframe>
<iframe src="doc.pdf" name="itempane"   ></iframe>

使用Chrome浏览器,我可以从菜单栏导航到父窗口,然后再回到包含pdf的框架以进行打印

Using chrome I can navigate from the menu bar to the parent and back down to the frame containing the pdf in order to print it

var pWindow = window.parent;
pWindow['itempane'].print();

尝试在IE11中执行相同操作会产生无效的调用对象错误.

Attempting to do the same in IE11 gives an Invalid calling object error.

您可以在 http://www.abhrdev.co.uk/main.html上看到此内容

我在做什么错/IE在做什么?

What am I doing wrong / what is IE doing differently?

欢呼

已更新.....

我认为我已经证明这不是JavaScript编码问题,而是与IE中的pdf处理有关.随着下一页

I think I have proved that this is not a javascript coding issue but related to the pdf handling in IE. With the following page

<a href="javascript:printFromMain('pdfpane');">Print PDF</a><br/>
<a href="javascript:printFromMain('htmlpane');">Print HTML</a>
<iframe src="bar_1.html" name="menu"  ></iframe>
<iframe src="doc.pdf" name="pdfpane"   ></iframe>
<iframe src="doc.html" name="htmlpane"   ></iframe>

和此功能

function printFromMain(paneName) {
var pWindow = window[paneName];
pWindow.focus();
pWindow.print();
}

可以打印html页面,但不能打印pdf,pWindow.focus()会给无效的调用对象-关于为什么可以很好接收的任何见解

the printing of the html page works but not the pdf the pWindow.focus() gives Invalid Calling Object - any insight into why that might be greatfully recieved

推荐答案

尝试了几件事之后,我终于可以在IE11中使用它了:

After trying several things, I finally go this to work in IE11:

1)使用对象代码代替iframe

1) use an object tag instead of iframe

2)直接在元素上运行focus()/print()

2) run focus() / print() directly on the element

3)在超时后运行,以确保加载了所有内容.可能有更好的方法(例如使用某些事件侦听器),因为超时时间需要相当长的时间才能正常工作

3) run after a timeout, to make sure everything in is loaded. There may be a better way (like using some event listener) to do this, as the timeout time needs to be fairly long for it to work properly

setTimeout(function () {
    var contentThingy = document.getElementById('itempane');
    contentThingy.focus();
    contentThingy.print();
}, 4000);

对象(具有指定ID)而不是iframe:

Object (with a specified id) instead of iframe:

<object id="itempane" ... ></object>

注意:不适用于Chrome.其他答案(例如,使用ContentWindow)中的其他变体之一.

Note: doesn't work in chrome. One of the other variations in the other answers (i.e. using ContentWindow) may.

这篇关于带有pdf的ie11中的javascript框架导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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