【问题标题】:javascript frame navigation in ie11 with a pdf带有pdf的ie11中的javascript框架导航
【发布时间】:2014-11-10 07:59:15
【问题描述】:

我有一个简单的网页,其中一个框架显示一个 pdf,另一个框架显示一个菜单栏。

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

使用 chrome,我可以从菜单栏导航到父级,然后返回到包含 pdf 的框架以便打印它

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

尝试在 IE11 中执行相同操作会导致调用对象无效错误。

你可以在http://www.abhrdev.co.uk/main.html看到这个

我做错了什么/IE 有什么不同?

干杯

更新.....

我想我已经证明这不是 javascript 编码问题,而是与 IE 中的 pdf 处理有关。与以下页面

<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 页面的打印有效,但 pWindow.focus() 提供的 pdf 无效调用对象 - 任何关于为什么可能会被广泛接收的见解

【问题讨论】:

  • 您的示例链接上的小注释...我认为这不是根本原因,但您的页面缺少 &lt;body&gt; 标记。
  • @mplungjan 调用来自 iframe,因此它需要父级。
  • 谢谢,添加了正文标签并更改了文档类型以整理它。窗口["itemane"].print();给出无法获取未定义或空引用的属性“打印”

标签: javascript pdf internet-explorer-11 frames


【解决方案1】:

在尝试了几件事之后,我终于在IE11中工作了:

1) 使用对象标签而不是 iframe

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

3) 超时后运行,以确保加载所有内容。可能有更好的方法(比如使用一些事件监听器)来做到这一点,因为超时时间需要相当长才能正常工作

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

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

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

注意:在 chrome 中不起作用。其他答案中的其他变体之一(即使用 ContentWindow)可能。

【讨论】:

    【解决方案2】:

    试试这个

    <iframe src="bar.html" name="menu"  ></iframe>
    <iframe src="doc.pdf" ID="itempane"   ></iframe>
    
    
    var otherPane = parent.document.getElementById("itempane");
    otherPane.focus(); // OR
    otherPane.print(); // OR
    
    var doc = otherPane.contentWindow || otherPane.contentDocument;
    doc.focus();
    doc.print();  
    

    【讨论】:

    • 我今天11号试试
    【解决方案3】:

    尝试实际使用window.frames 来获取frameList 并以这种方式通过框架名称引用它。

    var pWindow = window.parent;  //reference the parent from the iframe
    var ifr = pWindow.frames.itempane;  //get the pdf frame from the frame list
    ifr.focus();  
    ifr.print();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多