简体   繁体   English

在没有 JQuery 的情况下使用 JavaScript 调用 github:davidjbradshaw/iframe-resizer?

[英]Calling the github:davidjbradshaw/iframe-resizer using JavaScript without JQuery?

I'm trying to use the https://github.com/davidjbradshaw/iframe-resizer iframe resizer and the example ( https://github.com/davidjbradshaw/iframe-resizer/tree/master/example ) seems to be based on JQuery.我正在尝试使用https://github.com/davidjbradshaw/iframe-resizer iframe resizer 和示例( https://github.com/davidjbradshaw/iframe-resizer/tree/master/example )似乎是基于在 JQuery 上。 Does anyone know how to call this via JavaScript only without using JQuery?有谁知道如何在不使用 JQuery 的情况下仅通过 JavaScript 调用它? Does it need a body onload or do I capture the onload event of the iframe?它是否需要主体 onload 或者我是否捕获 iframe 的 onload 事件? I'm confused on how to start using it (Invoke it).我对如何开始使用它感到困惑(调用它)。

Edit...to add more details per questions.编辑...为每个问题添加更多详细信息。

  1. Why?为什么? Dynamic content: I need my iframe to dynamically adjust its height based on the "changing" content within the iframe.动态内容:我需要 iframe 根据 iframe 中“变化”的内容动态调整其高度。 I've tried a number of solutions like the one below but they do not " entirely " solve the problem 100% of the time.我已经尝试了许多解决方案,例如下面的解决方案,但它们并不能 100% 地“完全”解决问题。 They set the size only based on the "first page" of the iframe content:他们仅根据 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. Existing Docs./Not figuring it out: I'm not following the existing documentation provided by DavidBradshaw on how to do this: I tried adding this code as follows.现有文档。/未弄清楚:我没有遵循 DavidBradshaw 提供的有关如何执行此操作的现有文档:我尝试按如下方式添加此代码。 But apparently, that is NOT how you do it.但显然,这不是你做的。

The body of the file is:文件的主体是:

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

The script portion:脚本部分:

    <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>

Also at the called content within the iframe, I have this line of code.同样在 iframe 中的被调用内容中,我有这行代码。 I'm pretty sure this part is correct, though.不过,我很确定这部分是正确的。

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

Thanks in advance for the help.在此先感谢您的帮助。 I apologize if I seem dense or its a stupid question but I see the example prototyped: iFrameResize([{options}],[selector]);如果我看起来很笨拙或者是一个愚蠢的问题,我深表歉意,但我看到了原型示例: iFrameResize([{options}],[selector]);

However, don't you need an "event" to trigger that function?但是,您不需要“事件”来触发该功能吗? See my code and I use the onload event and it doesn't work.查看我的代码,我使用了 onload 事件,但它不起作用。 If I set the ID of the iframe to establish a [selector]:如果我设置 iframe 的 ID 来建立一个 [选择器]:

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

and call it like:并称之为:

    iFrameResize(,testframe);

or this:或这个:

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

It still doesn't work.它仍然不起作用。 I don't have any options and want to keep the options as default.我没有任何选项,并希望将这些选项保留为默认值。

You can do either.你也可以。

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

or或者

iFrameResize(null,"#testframe");

您可以使用

iFrameResize(,'iframe#testframe');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM