Connecting Tech Pros Worldwide Help | Site Map

Refresh iframe

Jacob
Guest
 
Posts: n/a
#1: Mar 15 '06
How do I refresh an iframe via JavaScript from the parent page?

/Jacob

marss
Guest
 
Posts: n/a
#2: Mar 15 '06

re: Refresh iframe



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>

Jacob
Guest
 
Posts: n/a
#3: Mar 15 '06

re: Refresh iframe


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

/Jacob

marss
Guest
 
Posts: n/a
#4: Mar 15 '06

re: Refresh iframe



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.

Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#5: Mar 16 '06

re: Refresh iframe


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
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
#6: Mar 16 '06

re: Refresh iframe


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
Closed Thread


Similar JavaScript / Ajax / DHTML bytes