0

我的页面上有两个 iframe。一种称为导航,另一种称为内容。在加载 iframe 时,我调用以下函数:

function resizeIframe(obj) {
  if (obj.contentWindow != undefined && obj.contentWindow != null && obj.contentWindow.document != undefined && obj.contentWindow.document != null) {
  obj.style.height = obj.contentWindow.document.body.scrollHeight + 20 + 'px';
  obj.style.width = obj.contentWindow.document.body.scrollWidth + 'px';
  }
}

我像这样在 iframe 上调用上述函数

   <iframe src="Taxonomy.htm" name="navigation" id="navigation" width="250" height="900" seamless="true" onload="resizeIframe(this)"></iframe>         
   <div id="divContent"><script>
   document.write('<iframe src="' + newPath + '" id="content" name="content" width="700"   height="900" seamless="true" onload="javascript:resizeIframe(this)">');
   document.write('</iframe>');  
   </script></div>

doContentLoad()当单击导航中的链接时,我调用另一个函数Iframe,该函数如下所示:

function doContentLoad() {
      var navFrameElem = indow.parent.document.getElementById("navigation").contentWindow  || window.parent.document.getElementById("navigation").contentDocument;
      if (navFrameElem != null && navFrameElem.document) 
           navFrameElem = navFrameElem.document;
      if (navFrameElem != null) {
        if (navFrameElem.body.scrollHeight > 900) {                window.parent.document.getElementById("navigation").parentNode.parentNode.style.height = navFrameElem.body.scrollHeight + 130 + 'px';
          window.parent.document.getElementById("navigation").style.height = navFrameElem.body.scrollHeight + 130 + 'px';
          navFrameElem.body.style.height = navFrameElem.body.scrollHeight + 'px';
        }
    }

    var contentFrameElem = window.parent.document.getElementById("content").contentWindow || window.parent.document.getElementById("content").contentDocument;
    if (contentFrameElem != null && contentFrameElem.document != null &&  contentFrameElem.document) contentFrameElem = contentFrameElem.document;               window.parent.document.getElementById("content").style.height = contentFrameElem.body.scrollHeight + 30 + 'px';   
     }

Firefox : Error: Permission denied to access property 'document'我在这两个函数中都收到以下错误。

IE I get: invalid calling object.

如何在此处获取文档对象?还是有更好的调整大小Iframes

4

1 回答 1

1

因为您包含 PDF 而不是 HTML 页面,所以 iframe contentWindow 没有 DOM,因此 JavaScript 无法访问 iFrame 中的任何属性。

于 2014-03-12T21:07:19.187 回答