Javascript – How to check whether (X) button in clicked in popup window

htmljavascript

I am trying to set the value to the hidden field in parent window from child window and want to set the value to the parent window only when popup window is closed.

This is working fine when i use button to close the window.

The script for the button is:
onclick="javascript:window.close();"

But the same condition fails when i click (X) button in title bar. Can anyone help me out with this issue

Best Answer

best way to do this is to use window.onunload but this event is also fired when you press ctrl+r (i.e. on refresh) so just check this out.