简体   繁体   English

如果由OnClick加载iframe,则自动调整iframe不起作用

[英]Auto Resize iframe Not Work If Iframe Loaded By OnClick

I'm building a site that can only be seen through an iframe. 我正在建立一个只能通过iframe看到的网站。 I also added a script that auto resize height can be adjusted. 我还添加了一个可以调整自动调整高度的脚本。

But loading my blog so the added weight of having to load two pages at once. 但加载我的博客所以增加了必须一次加载两个页面的重量。 To cope, I apply the OnClick to load the iframe. 为了应对,我应用OnClick来加载iframe。

Auto Resize But it turned out to not work. 自动调整大小但事实证明不起作用。

Load Iframe code: 加载iframe代码:

<script type="text/javascript">
function okeBos() {
document.getElementById("iframeControl").innerHTML='<iframe scrolling="no" src="http://name-domain.com" style="border: 0; width: 100%;"></iframe>';document.getElementById("starApps").style.display="none";
};
</script>

<div id="iframeControl"></div><div id="starApps"><span onclick="okeBos()">Load Iframe</span></div>

Do you know how to work the Auto Resize for tricks like this? 你知道如何使用这样的技巧来自动调整大小吗? Please help me, thanks .. 请帮帮我,谢谢..

EDIT 编辑

The following code snippet Resize My 以下代码片段调整我的大小

Stored at sites that are loaded: 存储在已加载的站点:

<script src='http://britha.com/Upload/MyFile/iframeResizer.contentWindow.min.js' type='text/javascript'></script>
<script>
    var iFrameResizer = {
        messageCallback: function(message){
        }
    }
</script>

Stored at the site containing the iframe: 存储在包含iframe的网站:

<script src="http://britha.com/Upload/MyFile/iframeResizer.js" type="text/javascript"></script>
<script type="text/javascript">
    iFrameResize({
        log                     : true,
        enablePublicMethods     : true,
        enableInPageLinks       : true,
    });
</script>

UPDATE UPDATE

What I know about iframes is that they are usually the last on the DOM to load, so you have to expect a lag sometimes. 我对iframe的了解是,它们通常是加载DOM的最后一个,所以你不得不期待一个滞后。 I have neglected to ask if you can even load an iframe successfully by normal means (ie in the markup (HTML)). 我忽略了问你是否可以通过正常方式(即在标记(HTML)中)成功加载iframe。 Anyways, I strongly suggest that you load your iframe the normal way because it won't be recognized by the iframe-resizer plugin. 无论如何,我强烈建议您以正常方式加载iframe,因为iframe-resizer插件无法识别它。 It has to coordinate between 2 pages, calculate, and adjust so I'm pretty sure it takes loading times into account. 它必须协调2页,计算和调整,所以我很确定它需要加载时间。 An iframe that pops up whenever the user decides to press a button is like 5 years to a computer (not scientific fact just an exaggeration). 每当用户决定按下按钮时弹出的iframe对于计算机来说就像5年(不是科学事实只是夸大其词)。

I have made a Plunker and used the example provided by this repository and I added some of my own tests as well. 我制作了一个Plunker并使用了这个存储库提供的示例,我也添加了一些自己的测试。 Here is the most important code: 这是最重要的代码:

Parent Page 父页面

<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script src="http://cdn.jsdelivr.net/iframe-resizer/3.5.3/iframeResizer.min.js"></script>
<script>
iFrameResize({options});

Child Page 儿童页面

<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script src="http://cdn.jsdelivr.net/iframe-resizer/3.5.3/iframeResizer.contentWindow.min.js"></script>
<script>

MOST IMPORTANT: DO NOT CREATE THE IFRAME DYNAMICALLY 最重要的是:不要动态创建IFRAME

PLUNKER PLUNKER


OLD


Please explain how it doesn't work. 请解释它是如何工作的。 It functions in this Snippet...How am I supposed to know what to fix if I do not have the auto-resize script? 它在这个片段中运行...如果我没有自动调整大小脚本,我该怎么知道要修复什么?

SNIPPET SNIPPET

 <script> function okeBos() { document.getElementById("iframeControl").innerHTML='<iframe scrolling="no" src="http://name-domain.com" style="border: 0; width: 100%;"></iframe>'; document.getElementById("starApps").style.display="none"; }; </script> <div id="iframeControl"></div> <div id="starApps"> <span onclick="okeBos()">Load Iframe</span> </div> 

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

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