468,316 Members | 1,509 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,316 developers. It's quick & easy.

Refresh iframe

How do I refresh an iframe via JavaScript from the parent page?

/Jacob

Mar 15 '06 #1
5 177039

Jacob wrote:
How do I refresh an iframe via JavaScript from the parent page?

/Jacob


<html>
<head>
<script type="text/javascript">

function Reload () {
var f = document.getElementById('iframe1');
f.src = f.src;
}

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

Mar 15 '06 #2
Is there no way to use location.refresh or location.reload?

/Jacob

Mar 15 '06 #3

Jacob wrote:
Is there no way to use location.refresh or location.reload?

/Jacob


var f = document.getElementById('iframe1');
f.contentWindow.location.reload(true);

Value of parameter in the brackets :

false - Default. Reloads the page from the browser cache.
true - Reloads the page from the server.

But I don't know whether it works elsewere besides IE.

Mar 15 '06 #4
Jacob wrote:
How do I refresh an iframe via JavaScript from the parent page?


window.frames[...].reload(...);

Might not be pretty, is completely proprietary, but it works always.
Even with different second-level domains.
PointedEars
Mar 16 '06 #5
marss wrote:
Jacob wrote:
Is there no way to use location.refresh or location.reload?


var f = document.getElementById('iframe1');
f.contentWindow.location.reload(true);

Value of parameter in the brackets :

false - Default. Reloads the page from the browser cache.
true - Reloads the page from the server.

But I don't know whether it works elsewere besides IE.


It also works in Gecko, in fact the Location object and its reload()
method (along with the meaning of the argument) were introduced in
NN 3.0 (JavaScript 1.0 then). However, this solution has its
shortcomings:

- it requires implementation of HTMLDocument::getElementById()
(not before IE 5.0)
- it requires an ID for the `iframe' element,
(or implementation of HTMLDocument::getElementsByTagName();
not before IE 5.0)
- it requires support of the `contentWindow' property
(not before IE 5.5)

DOM Level 0 suffices here, works _always_ and most certainly _everywhere_
(except if client-side script support is unavailable).
PointedEars
Mar 16 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by Conax | last post: by
2 posts views Thread by Jeronimo Bertran | last post: by
21 posts views Thread by javainfo | last post: by
reply views Thread by Abhishek Srivastava | last post: by
1 post views Thread by spolsky | last post: by
reply views Thread by NPC403 | last post: by
1 post views Thread by howard w | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.