363,924 Members | 2603 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

Refresh iframe

Jacob
P: n/a
Jacob
How do I refresh an iframe via JavaScript from the parent page?

/Jacob

Mar 15 '06 #1
Share this Question
Share on Google+
5 Replies


marss
P: n/a
marss

Jacob wrote:[color=blue]
> How do I refresh an iframe via JavaScript from the parent page?
>
> /Jacob[/color]

<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

Jacob
P: n/a
Jacob
Is there no way to use location.refresh or location.reload?

/Jacob

Mar 15 '06 #3

marss
P: n/a
marss

Jacob wrote:[color=blue]
> Is there no way to use location.refresh or location.reload?
>
> /Jacob[/color]

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

Thomas 'PointedEars' Lahn
P: n/a
Thomas 'PointedEars' Lahn
Jacob wrote:
[color=blue]
> How do I refresh an iframe via JavaScript from the parent page?[/color]

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

Thomas 'PointedEars' Lahn
P: n/a
Thomas 'PointedEars' Lahn
marss wrote:
[color=blue]
> Jacob wrote:[color=green]
>> Is there no way to use location.refresh or location.reload?[/color]
>
> 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.[/color]

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

Post your reply

Help answer this question



Didn't find the answer to your JavaScript / Ajax / DHTML question?

You can also browse similar questions: JavaScript / Ajax / DHTML iframe refresh refresh iframe