且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在加载后强制重新加载iFrame

更新时间:2022-12-07 09:00:46

所有这些线索都已经死了,但我找到了一个有效的代码片段。不是我写的,我不记得它是从哪里来的。

 < div class =overlay-content>只需发帖即可帮助某人应该有同样的问题。 // CSS所需的内容容器样式



< div id =Reloader> // iFrame将被重新加载到这个div中

< / div>



//在页面载入
时脚本重新载入iframe< script>
函数aboutReload(){
$(#Reloader)。html('< iframe id =Reloaderheight =355pxwidth =830pxscrolling =noframeborder = 0src =about.html>< / iframe>');
}
< / script>



< / div>

基本上只是在带有iFrame的窗口打开时加载iFrame源代码,而不是在加载iFrame时原始页面加载。

I have numerous iframes that load specific content on my pages. Both the parent and iframe are on the same domain.

I have a scrollbar inside the iframe that doesn't seem to load correctly in all browsers. But when I refresh the iframe it loads perfect. I have no idea why it does this.

I have used the meta refresh, which works but I don't want the page to refresh constantly, just once.

The solution I'm looking for will reload the iFrame content after the iFrame is opened, with a minimal delay.

Thanks for your time and help!

-Brett

----------EDIT:--------

I realized that my page loads all of my iframes when the index is loaded. The iframes appear in a jQuery overlay, which is also loaded but visibility:hidden until called. So on this call is when I would want the iframe to be reloaded.

Could anyone help me come up with a Javascript function that reloads the iFrame when I click the link to the iFrame? I've gotten close but I know nothing about js and I keep falling short. I have a function that reloads the page, but I can't figure out how to get it called just once.

I have this so far:

<script type="text/javascript">

var pl;
var change;
pl=1;

function ifr() {

if (pl=1) {
    document.location.reload([true]);
    alert("Page Reloaded!");
    change=1;
    return change;
}

change+pl;

}

So basically it uses the document.location.reload which works to reload the page. I'm trying to then make pl change to something other than 1 so the function doesnt run again. I've been calling this JS from the body with onLoad.

All the leads on this went dead, but I did find a code snippet that worked. Not written by me, and I don't remember where it came from. Just posting to help someone should they ever have the same question.

<div class="overlay-content"> //Content container needed for CSS Styling



     <div id="Reloader"> //iFrame will be reloaded into this div

     </div>



           //Script to reload the iframe when the page loads
         <script>
            function aboutReload() { 
              $("#Reloader").html('<iframe id="Reloader" height="355px" width="830px" scrolling="no" frameborder="0" src="about.html"></iframe>');
            }
         </script>



</div>

Basically just loads the iFrame source when the window with the iFrame opens, as opposed to the iFrame loading when the original page loads.