Connecting Tech Pros Worldwide Help | Site Map

Refresh iframe

 
LinkBack Thread Tools Search this Thread
  #1  
Old March 15th, 2006, 11:55 AM
Jacob
Guest
 
Posts: n/a
Default Refresh iframe

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

/Jacob


  #2  
Old March 15th, 2006, 12:45 PM
marss
Guest
 
Posts: n/a
Default 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, 01:35 PM
Jacob
Guest
 
Posts: n/a
Default Re: Refresh iframe

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

/Jacob

  #4  
Old March 15th, 2006, 01:55 PM
marss
Guest
 
Posts: n/a
Default 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, 03:05 AM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
Default 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, 04:55 AM
Thomas 'PointedEars' Lahn
Guest
 
Posts: n/a
Default 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
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,662 network members.