Refresh iframe

M

marss

Jacob said:
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>
 
M

marss

Jacob said:
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.
 
T

Thomas 'PointedEars' Lahn

Jacob said:
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
 
T

Thomas 'PointedEars' Lahn

marss said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,260
Messages
2,571,038
Members
48,768
Latest member
first4landlord

Latest Threads

Top