...

View Full Version : Resolved Help refreshing iframe?



motionman95
07-26-2009, 12:25 AM
I need help. I'm trying to reload a frame using javascript. None of the code snippets I found on google work! I don't need to change the src, I just need to refresh it, with cookies intact and whatever varibles may have been passed.

Here's what I'm using:



<script type="text/javascript">
function myFunc(){
document.getElementById("p").location.reload(true);
}
</script>
<iframe id="p" src="http://google.com/"></iframe>
<a onClick="myFunc()">Refresh the frame!</a>


But it doesn't work! I'm really confused and don't know what to do.

randomuser773
07-26-2009, 12:47 AM
I need help. I'm trying to reload a frame using javascript.
Try:

document.getElementById( "p" ).contentWindow.location.reload( true );

mrhoo
07-26-2009, 12:48 AM
An iframe doesn't have a location object- it is just an html element.
You need to access the window object in the iframe-
document.getElementById("p").contentWindow may do it.

motionman95
07-26-2009, 01:06 AM
Try:

document.getElementById( "p" ).contentWindow.location.reload( true );

Doesn't work. :confused:

randomuser773
07-26-2009, 03:42 AM
Doesn't work. :confused:
What do you mean 'doesn't work'?
No effect at all?
No console errors?
Time to show the whole thing I'd say.

motionman95
07-26-2009, 04:49 AM
I didn't understand what you meant by "console errors" Googled and WALA! It will definitely become a tool in my coding arsenal.

Here's the error in Console:

Error: Permission denied for <file://> to get property Location.reload from <http://www.google.com>.
Source file: file:///C:/test.html
Line: 4

And the code is:


<html>
<script>
function theFunc(){
document.getElementById( "p" ).contentWindow.location.reload( true );
}
</script>
<body>
<iframe id="p" src="http://google.com"></iframe>
<a onClick="theFunc()>RELOAD FRAME</a>
</body>
</html>

randomuser773
07-26-2009, 06:01 AM
<iframe id="p" src="http://google.com"></iframe>
You're attempting cross-domain scripting, which isn't allowed.

motionman95
07-26-2009, 06:04 AM
So that's why! I think I know how to fix it, then.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum