Page 1 of 1
[solved]iframe contents refreshing their parent document?
Posted: Fri Oct 07, 2005 4:48 am
by robster
Hi all,
I have an iframe and I perform functions within it. An example is when a user modifies a transaction (within the iframe) it loads a seperate script to perform the modification, then after doing so, uses something like this to reload the iframe back to its original state:
Code: Select all
header("Location: pos_iframe_contents.php?clientid=$clientid&letter=$letter");
That's fine and it does so, but there are other things on that page that need to be refreshed when the iframe refreshes.
I want to use something like that header command to reload the iframe, but also to refresh the parent document.
Can this be done?
Any advice appreciated,
Rob
Posted: Fri Oct 07, 2005 6:04 am
by n00b Saibot
Code: Select all
<script>this.parent.location.reload()</script>
Posted: Fri Oct 07, 2005 6:36 am
by robster
So when the original script is reloaded with the header command I then call that script to reload the whole page?
That's kind of double reloading.
I'll do it if there's no other way, but is there a more elegant way to reload the whole parent page without having to head back to relod the iframe first?
I was hoping you could do something like this:
Code: Select all
header("Location: PARENT.pos_iframe_contents.php?clientid=$clientid&letter=$letter");
That doesn't work of course, but is there something similar?
Posted: Fri Oct 07, 2005 6:48 am
by n00b Saibot
header() is PHP & that is JS. both have differences you know

and I was thinking of refreshing the whole page since its needed but won't the iframe also refresh when the whole page is refreshed and the located will be reverted automatically. I don't see the need for a header().
Posted: Fri Oct 07, 2005 7:11 am
by robster
the iframe does refresh when the WHOLE page refreshes, except when i use header to reload the previous file that the new iframe file came from, it does not reload the rest of the page.
Perhaps this diagramme will help:
I guess what i need, is rather than the iframe reloading just the iframe, i want it to go back and refresh the main document (the parent) which will do the same thing and have the added bonus of refreshing everything in the main document (my primary objective with this problem).
I hope that's clearer, and I suspect I may be missing something you're saying.... maybe the implimentation of that script...?
Rob
Posted: Fri Oct 07, 2005 7:32 am
by n00b Saibot
robster wrote:i want it to go back and refresh the main document (the parent) which will do the same thing and have the added bonus of refreshing everything in the main document (my primary objective with this problem).
Back

window.history.go(-1);
Refresh

document.location.reload();
Have your choice

Posted: Fri Oct 07, 2005 7:36 am
by robster
omg! so easy! I feel a bit of a twat. I guess then, the next question (I'm a complete neub at javascript) is... How can I actually trigger that javascript?
I know how to do onclicks, and onmouse events ect, but how can i do it inline?
Here is my code:
Code: Select all
<?
$clientid = $_GET['clientid']; //get the client id from the post data
$letter = $_GET['letter']; //get the letter from the post data
$id = $_GET['id']; //get the letter from the post data
$price = $_GET['price']; //get the letter from the post data
include "config.php";
include "functions_salon.php";
$Update = mysql_db_query ($dbname, "UPDATE transactions_tmp SET price = $price WHERE id = '$id'") or die('Could not edit price: ' . mysql_error());
header("Location: pos_iframe_contents.php?clientid=$clientid&letter=$letter");
?>
Posted: Fri Oct 07, 2005 7:51 am
by n00b Saibot
replace header() bit with echo "javascript here..."; ASAT (As Simple As That

)
Posted: Sat Oct 08, 2005 2:11 am
by robster
thanks for that, I just had a go and using this I get an infinite reload loop:
Code: Select all
echo "<script language=\"JavaScript\"><!--document.location.reload(); //--></script> ";
and using this it does go back to the previous page (within the iframe) but does not refresh itself so it shows old content.
Code: Select all
echo "<script language=\"JavaScript\"><!-- window.history.go(-1); //--></script> ";
So I'm still kind of stuck. I like the idea of using the history.go(-1) to go back to the previous file, then using the document.location.reload to refresh it,but as I say, it just infinite loop reloads
Any advice?
Posted: Sat Oct 08, 2005 2:40 am
by n00b Saibot
In your IFrame
Code: Select all
echo <<<JS
<script language="JavaScript">
<!--
parent.history.go(-1);
parent.document.location.reload();
//-->
</script>
JS;
Posted: Sat Oct 08, 2005 3:29 am
by robster
wow... thanks!
I've not heard of a echo <<<JS before?!
I even just searched google, and nothing! Is it some secret underground php/javascript thing? LOL!
Really, thank you so much, it's working a treat! I would have though that telling script to go back in history would then stop execution of the js. That's pretty special that it keeps on executing, even when the browser has been sent back in history.

Posted: Sat Oct 08, 2005 4:11 am
by n00b Saibot
This operator (i have forgot its exact name

) tells PHP to output everything until the token after it (here, JS) is found. It comes very handy sometimes

Posted: Sat Oct 08, 2005 7:08 am
by feyd
n00b Saibot wrote:i have forgot its exact name

heredoc
http://php.net/language.types.string#la ... ax.heredoc
Posted: Sat Oct 08, 2005 7:17 am
by n00b Saibot
oh yes, i seem to be losing my memory early

first came across this op in Perl....