I've been trying to figure this out for a couple days. It seems like it should be simple, but apparently, it's not. How do I refresh an Iframe with Javascript?
I've been trying to figure this out for a couple days. It seems like it should be simple, but apparently, it's not. How do I refresh an Iframe with Javascript?
I don't really know, it might have a window object of it's own but I think this will work:
var refreshIFrame = function (iframeID) {
var src = document.getElementById(iframeID).src;
document.getElementById(iframeID).src = null;
document.getElementById(iframeID).src = src;
}
Well, I've tried this:
var a=document.getElementById("a");
a.src=a.src;
And that works, but only to a certain extent. I'll explain what I mean, so bear with me.
Let's say I have an iframe like this: <iframe src="http://google.com" name="ifram" id=a height=780 width=1075></iframe>
Now let's say that, for some reason, there's a link to yahoo.com on google.com. If I go to yahoo.com, and then try to do "a.src=a.src" then the iframe refreshes, but it goes back to google.com instead of refreshing yahoo.com.
Oh I see, well, I'll check on W3Schools and see if there's anything else I can find.
var refreshIFrame = function (iframeID) {
var url = document.getElementById(iframeID).contentDocument.URL;
document.getElementById(iframeID).contentDocument.URL = null;
document.getElementById(iframeID).contentDocument.URL = url;
}
There! That should work. contentDocument is like document but for the iframe, and then theres the URL. Anything that might not work?
Last edited by ???; 07-01-2007 at 03:33 PM.
I looked at the firefox error console and it said this: "Error: uncaught exception: Permission denied to get property HTMLDocument.URL"
Well for me it just said it's a read only var. But that sucks.
I tried this:
"function refreshIFrame(iframeID) {
var a=document.getElementById(iframeID);
var url = a.contentWindow.URL;
a.contentWindow.URL = null;
a.contentWindow.URL = url;
}"
And in IE, it said "Permission Denied."
Should be more simple than that.
It works with or without the part in red, but I'm assuming that may not be the case for all browsers. Test it yourself.Code:<iframe name="test" src="a.htm" width="200" height="200"></iframe> <a href="#" onClick="frames.test.location='b.htm';">click</a>
That's a working chunk of html for a page, but if you just want the script itself:
framename.location='newpage.htm';
However, since you're wanting it to refresh, use [frame].src to get the current value.
Here's a function that should work:However, it doesn't seem to work for me. I've tried various combinations and it's not doing anything. Someone should know. I'm just guessing.Code:function refreshframe(id) { frames.id.location=frames.id.location; }
This does work, though, with specifying a particular frame in the script (frames.myname.location for example), so it's something about passing the name to the id variable.
Note that though you are specifying an iframe, this would work for any frame, so there is no need to specify the refresh script as for iframes.
Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum
Is it possible that it's not working because my page and the other page are on different domains?
Bookmarks