Callback from closing window does not fire?

Callback from closing window does not fire?

Hi everyone,

I am working on a cms and I have a button which will open a window where the users can input data.
I bound a beforeunload event, but it does not always work.

Anyone have any ideas? Here is my code:


  1. $('#addText').live('click'function(e{
  2.     $(window.open("http://www.website.com/cms/addText.html""mywindow""menubar=1,resizable=1,width=550,height=450")).bind('beforeunload'function({
  3.         $(this).unbind('beforeunload');
  4.         loadFreshContent('text');
  5.     });
  6. });

Those two lines don't get called when I close the window, at least not always:

  1. $(this).unbind('beforeunload');
  2. loadFreshContent('text');

Thanks in advance for any help and tips!