Connecting Tech Pros Worldwide Help | Site Map

Refresh iframe

  #1  
Old March 15th, 2006, 12:55 PM
Jacob
Guest
 
Posts: n/a
How do I refresh an iframe via JavaScript from the parent page?

/Jacob

  #2  
Old March 15th, 2006, 01:45 PM
marss
Guest
 
Posts: n/a

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>

  #3  
Old March 15th, 2006, 02:35 PM
Jacob
Guest
 
Posts: n/a

re: Refresh iframe


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

/Jacob

  #4  
Old March 15th, 2006, 02:55 PM
marss
Guest
 
Posts: n/a

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.

  #5  
Old March 16th, 2006, 04:05 AM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a

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
  #6  
Old March 16th, 2006, 05:55 AM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a

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 Threads
Thread Thread Starter Forum Replies Last Post
No Page_Load event when loading .aspx page into iframe epower answers 1 October 14th, 2007 05:29 AM
Opera doesn't refresh IFrame spolsky answers 1 August 8th, 2006 10:15 PM
IFRAME & AJAX javainfo answers 21 March 18th, 2006 01:05 AM