简体   繁体   中英

HTML - difference between iframe reload and parent reload

Inside "myIframe":

When I reload the Iframe, my javascript inside this page is not executed:

myIframe:

alert("reloaded");
$('.selectedTab').click(function() {
     document.getElementById("myIFrame").contentDocument.location.reload(true);
});

But if I reload its parent page the javascript is reloaded.

parent.location.reload();


what is the difference between these two approachs?
It is possible to reload an Iframe contain without passing by the parent page and without requesting the server, just "replay" with the data already got?

As Kevin B mentioned this seems to be an issue with the content location. Make sure the Iframe src is also served from the same domain as parent.

http://jsfiddle.net/55Ewm/ - seems to work fine for me.

<script>
window.onload = function() {
   alert("reloaded");
   $('.selectedTab').click(function() {
       document.getElementById("myIFrame").contentDocument.location.reload(true);
   });
}
</script>

<button class="selectedTab">Reload Iframe</button>
<iframe id="myIFrame" src="/" />

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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