By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,106 Members | 2,686 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,106 IT Pros & Developers. It's quick & easy.

reload iframe for individual and all iframes on page

P: 2
I have a page with multiple iframes and need to have the user (ie6) be able to click a button to refresh any one of the iframes - but also to click another button at the top of the page to refresh all of them - from the server (this could be on page refresh also) as the purpose is to reset the iframe to the original content in case the user clicked on a link in that iframe and changed it, but also in case there were updates to the original page since the last load. The page hosting the iframes is in a frameset.

I used the following code from an older thread but (as I don't know javascript) when I modified it to include two iframes for a test it didn't work. It refloads only the first iframe when clicking either button. Reloading the whole page doesn't reload the iframes if they have been changed, and I need that (again, from the server), too.

This needs to be manual reloading as the info in the iframe may be in use at any moment and I can't have it vanish unexpectedly even for a few seconds.

Also, is there any way to block break out of frames code for an iframe?

Your help is much appreciated!

[HTML]<html>
<head>

<script type="text/javascript">
function Reload () {
var f = document.getElementById('iframe1','iframe2');
f.src = f.src;
}
</script>

</head>
<body>
<iframe id="iframe1" height="200" width="900"
src="http://google.com"></iframe>
<br>
<input type="button" value="Reload Original CSI Content" onclick="Reload();">

<iframe id="iframe2" height="200" width="900"
src="http://google.com"></iframe>
<br>
<input type="button" value="Reload Original CSI Content" onclick="Reload();">
</body>
</html>[/HTML]
Jan 25 '08 #1
Share this Question
Share on Google+
2 Replies


gits
Expert Mod 5K+
P: 5,333
hi ...

use something like the following instead. this will reload all iframes in your page.

Expand|Select|Wrap|Line Numbers
  1. function reload_iframes() {
  2.     var f_list = document.getElementsByTagName('iframe');
  3.  
  4.     for (var i = 0, f; f = f_list[i]; i++) {
  5.         f.src = f.src;
  6.     }
  7. }
kind regards
Jan 25 '08 #2

P: 2
I tried what you suggested, pasting it in the head section and it didnt reload the iframes when I used the browser reload button. I did different search terms in the google.com iframes and expected that the original blank would be reloaded in both iframes, but it came back with the same two pages of search results. What am I missing?

Again, I would especially like a button that would reload all the iframes on the page from the server, and without reloading the page itself.

Also, if you know a way to block break out of frames for iframes, this has been a problem with the page. Alternately, to disable javascript in pages in iframes only.
Jan 26 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.