techtheatre Posted September 3, 2007 Share Posted September 3, 2007 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! Quote Link to comment Share on other sites More sharing options...
techtheatre Posted September 3, 2007 Author Share Posted September 3, 2007 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! Quote Link to comment Share on other sites More sharing options...
techtheatre Posted September 3, 2007 Author Share Posted September 3, 2007 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! Quote Link to comment Share on other sites More sharing options...
techtheatre Posted September 3, 2007 Author Share Posted September 3, 2007 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! Quote Link to comment Share on other sites More sharing options...
techtheatre Posted September 3, 2007 Author Share Posted September 3, 2007 i have re-posted the last part of this in the AJAX section of this forum. Here is the link: http://www.phpfreaks.com/forums/index.php/topic,157804.0.html I am also marking this as "solved"...though the question does continue at the other location. Thanks. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.