Jump to content

[SOLVED] triggering action in parent window


techtheatre

Recommended Posts

i have a page (happens to be php) that initializes a javascript popup as follows:

<a href="option_edit.php?Action=edit&Id=$Id\" target=\"EditPage\" onclick=\"window.open('option_edit.php?Action=edit&Id=$Id','EditPage','height=255, width=400,toolbar=no,directories=no,status=no, menubar=no,scrollbars=no,resizable=no'); return false;">edit</a>

 

i want to run a javascript function in the main (parent) window when the popup is closed.  This function will reload the content of the window (actually the content of one section of the page using ajax) to reflect the change made with the popup.

 

Basically, when the popup is closed (which will hopefully happen either by a link click or automatically...both using onLoad="self.close();return false;" ) then the main window should execute a function like:  ajaxFunction();

 

i know pretty much nothing about javascript, but i tried the following with no success:

 

onLoad="parent.ajaxFunction();self.close();return false;"

 

Thank you in advance for any help you can provide!

 

Link to comment
Share on other sites

i am re-posting the above, because the banner ad seems to have resized the source code snippet i provided, so i think it may be easier to read marked as a quote rather than as code:


 

i have a page (happens to be php) that initializes a javascript popup as follows:

 

 

<a href="option_edit.php?Action=edit&Id=$Id\" target=\"EditPage\" onclick=\"window.open('option_edit.php?Action=edit&Id=$Id','EditPage','height=255, width=400,toolbar=no,directories=no,status=no, menubar=no,scrollbars=no,resizable=no'); return false;">edit</a>

 

 

i want to run a javascript function in the main (parent) window when the popup is closed.  This function will reload the content of the window (actually the content of one section of the page using ajax) to reflect the change made with the popup.

 

Basically, when the popup is closed (which will hopefully happen either by a link click or automatically...both using onLoad="self.close();return false;" ) then the main window should execute a function like:  ajaxFunction();

 

i know pretty much nothing about javascript, but i tried the following with no success:

 

onLoad="parent.ajaxFunction();self.close();return false;"

 

Thank you in advance for any help you can provide!

 

Link to comment
Share on other sites

So...i have found out that the "opener" window (originally i was calling this the "parent" since i did not know the correct terminology) can apparently be controlled using the following reference:

 

window.opener.document

 

Unfortunately, even armed with this information, i am still not sure how to run my function "ajaxFunction()" on that window.

 

I know i am making progress, but if anyone has time to point me in the right direction or tell me how to use window.opener.document (or something else) to run my function from the popup window, that would be awesome.

 

THANKS!

Link to comment
Share on other sites

okay...so i got it (mostly).  The following works:

 

onLoad="window.opener.ajaxFunction();self.close();return false;"

 

 

The only problem is (and this could be completely unrelated) that if i execute the function this way in Firefox, it never seems to complete the Ajax request.  It wirks perfectly in IE7.  Anyone know what the problem may be (i can post the source in a new thread if nobody has ideas without seeing it).  This is a pretty standard ajax request, and it is getting stuck in the "loading" loop (in firefox, not in IE):

ajaxRequest.onreadystatechange = function(){
				if(ajaxRequest.readyState == 4)
				{
					if (ajaxRequest.status == 200)
					{
						// SUCCESS							
						// the next line inserts retrieved data into a DIV area called <AjaxContentDiv>
						document.getElementById('AjaxContentDiv').innerHTML=ajaxRequest.responseText;
					}
					else
					{
						// this might be a 404 if the page is missing (or other error number)
						alert(\"ERROR:  Page status is \" + ajaxRequest.status);
						return false;
					}
				}
				else
				{
					// readyState has changed but <> 4
					document.getElementById('AjaxContentDiv').innerHTML = '<img src=\"images/ajax_loading.gif\"> LOADING...';
				} 

 

Thanks!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.