3

我正在尝试使用https://github.com/davidjbradshaw/iframe-resizer iframe resizer 和示例(https://github.com/davidjbradshaw/iframe-resizer/tree/master/example)似乎是基于在 JQuery 上。有谁知道如何在不使用 JQuery 的情况下仅通过 JavaScript 调用它?它需要正文 onload 还是我捕获 iframe 的 onload 事件?我对如何开始使用它感到困惑(调用它)。

编辑...为每个问题添加更多详细信息。

  1. 为什么?动态内容:我需要 iframe 根据 iframe 中“变化”的内容动态调整其高度。我已经尝试了多种解决方案,例如下面的解决方案,但它们并没有“完全”100% 地解决问题。他们仅根据 iframe 内容的“第一页”设置大小:

    <script type="text/javascript">
    <!--
    //Credit for script: http://th.atguy.com/mycode/100_percent_iframe/
    <script language="JavaScript">
    
    function resize_iframe()
    {
    
    var height=window.innerWidth;//Firefox
    if (document.body.clientHeight)
    {
        height=document.body.clientHeight;//IE
    }
    //resize the iframe according to the size of the
    //window (all these should be on the same line)
    document.getElementById("glu").style.height=parseInt(height-
    document.getElementById("glu").offsetTop-8)+"px";
    }
    
    // this will resize the iframe every
    // time you change the size of the window.
    window.onresize=resize_iframe; 
    
    //Instead of using this you can use: 
    //  <BODY onresize="resize_iframe()">
    //--></script>
    
  2. 现有文档。/未弄清楚:我没有遵循 DavidBradshaw 提供的有关如何执行此操作的现有文档:我尝试按如下方式添加此代码。但显然,这不是你的做法。

该文件的主体是:

    <iframe src="http://www.domain.net/store20/StoreTop.aspx?StoreID=17" width="100%" scrolling="no" onload="iFrameResize()"></iframe>

脚本部分:

    <script type="text/javascript" src="../src/iframeResizer.min.js"></script> 
    <script type="text/javascript">
    <!--
    <script language="JavaScript">
    iFrameResize(); 
    // this will resize the iframe every
    // time you change the size of the window.
    window.onresize=iFrameResize; 
    //Instead of using this you can use: 
    //  <BODY onresize="resize_iframe()">
    //--></script>

同样在 iframe 中的被调用内容处,我有这行代码。不过,我很确定这部分是正确的。

    <script type="text/javascript" src="../js/iframeResizer.min.js"></script> 

在此先感谢您的帮助。如果我看起来很密集或这是一个愚蠢的问题,我深表歉意,但我看到了原型示例: iFrameResize([{options}],[selector]);

但是,您不需要“事件”来触发该功能吗?查看我的代码,我使用了 onload 事件,但它不起作用。如果我设置iframe的ID来建立一个[选择器]:

    <iframe id="testframe" src="http://www.domain.net/store20/StoreTop.aspx?StoreID=17" width="100%" scrolling="no" onload="iFrameResize()"></iframe>

并称之为:

    iFrameResize(,testframe);

或这个:

    iFrameResize(,$("#testframe"));

它仍然不起作用。我没有任何选项,并希望将选项保留为默认值。

4

2 回答 2

3

你可以做任何一个。

$("#testframe").iFrameResize();

或者

iFrameResize(null,"#testframe");
于 2015-03-10T19:39:38.537 回答
0

您可以使用

iFrameResize(,'iframe#testframe');
于 2014-11-10T08:07:16.463 回答