PDA

View Full Version : making an ajax call in the opener of a window



redman
Jul 13th, 2007, 11:13 AM
hi,

i've got a page that when you click on a link, javascript opens a new window. what i'm trying to do is make it so that when the new window is closed, a callback function is executed that uses ajax to update the document in the opener window.

i'm using jquery, but that's just to make things easier. here's the code i've put in the new window:

$(window).unload(function() { window.opener.refreshPage(); });

pretty simple - it just calls the window.opener.refreshPage method when the new window's onUnload event is triggered.

in the opener window's document, there is a function, refreshPage that makes a simple ajax call. The ajax call works fine when i run it myself from within the browser on the opener document. however, when i close the new window, refreshPage is called, but the post request doesn't run. i'm using firefox, and firebug doesn't give a specific error. i think what's happening is because refreshPage is being called from a window just before it is closed, that execution of refreshPage is terminated milliseconds after it begins.

so, my question is, how can i run a callback function when a new window is closed?

thank in advance,
al

redman
Jul 13th, 2007, 11:19 AM
problem solved. this web page helped me fix it:

http://www.captain.at/howto-ajax-parent-opener-window-close-error.php