[solved]iframe contents refreshing their parent document?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

[solved]iframe contents refreshing their parent document?

Post 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
Last edited by robster on Sat Oct 08, 2005 6:24 am, edited 1 time in total.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

:arrow:

Code: Select all

<script>this.parent.location.reload()</script>
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

Post 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?
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post 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().
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

Post 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:
Image

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
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post 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 :arrow: window.history.go(-1);
Refresh :arrow: document.location.reload();

Have your choice ;)
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

Post 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");  
	
	

?>
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

replace header() bit with echo "javascript here..."; ASAT (As Simple As That ;) )
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

Post 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?
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

In your IFrame :arrow:

Code: Select all

echo <<<JS
<script language="JavaScript">
<!--
parent.history.go(-1);
parent.document.location.reload();
//-->
</script>  
JS;
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

Post 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.

:)
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post 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 ;)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

n00b Saibot wrote:i have forgot its exact name :?
heredoc

http://php.net/language.types.string#la ... ax.heredoc
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

oh yes, i seem to be losing my memory early :| first came across this op in Perl....
Post Reply