How to force restart iFrame after boot

I have many iframes that upload specific content to my pages. Both the parent and iframe are in the same domain.

I have a scrollbar inside an iframe that doesn't seem to load correctly in all browsers. But when I update the iframe, it loads perfectly. I have no idea why he is doing this.

I used meta-update, which works, but I do not want the page to be updated constantly, only once.

The solution I'm looking for will reload the contents of the iFrame after opening the iFrame with minimal delay.

Thanks for your time and help!

-Brett

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

I realized that my page loads all my frames when loading the index. Iframes appear in a jQuery overlay, which also loads, but visibility: hidden until called. So this is a call when I want the iframe to reboot.

Can someone help me come up with a Javascript function that reloads iFrame when I click on the iFrame link? I closed, but I know nothing about js and I keep falling behind. I have a function that reloads the page, but I cannot figure out how to call it right away.

I still have this:

<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 document.location.reload, which works to reload the page. I am trying to change pl to something other than 1, so the function does not start again. I called this JS from the body using onLoad.

+4
source share
4 answers

All conclusions about this died, but I found a piece of code that worked. It is not written by me, and I do not remember where it came from. Just post to help someone if 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> 

It basically just loads the iFrame source when the window opens with the iFrame, unlike loading the iFrame when loading the original page.

+8
source

Besides the volume of the original question, however, this jQuery snippit works with crossram iframes where the contentDocument.location.reload (true) method will not be associated with the sandbox.

 //assumes 'this' is the iframe you want to reload. $(this).replaceWith($(this).clone()); //Force a reload 

It basically replaces the whole iframe with a copy of itself. We use it to force resize of built-in third-party "dumb" widgets, such as video players, which do not notice when their size changes.

+3
source

In the iframe element, set onload:

 iframe.onload = function() {this.contentWindow.location.reload(); this.onload = null;}; 

(only works if the iframe location is in the same domain as the main page)

+2
source

Here's a complete solution to the original question:

 <iframe onload="reloadOnce(this)" src="test2.html"></iframe> <script> var iframeLoadCount = 0; function reloadOnce(iframe) { iframeLoadCount ++; if (iframeLoadCount <= 1) { iframe.contentWindow.location.reload(); console.log("reload()"); } } </script> 

The updated question is not entirely clear (what is the “iFrame link” and where is it in your snippet?), But you have some problems with the code:

  • "calling this JS from the body with onLoad", assuming you mean the iframe body, means that the variable that you hope to use to avoid endless reloading will be knocked down along with the rest of the iframe page when it reloads. You need to either load a slightly different url in the iframe (and check the url on iframe onload before reloading), or put the flag variable on the external page (and access it using parent. VariableName), which should work, I think )
  • if (pl=1) { should use == , since = always the destination.
  • change+pl; has no effect.
+2
source

All Articles