views:

652

answers:

4

Hi,
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

+3  A: 

Use onBeforeUnload.

jeffamaphone
I am using struts tags in this jsp to dispaly error message.<s:if test="hasActionErrors()"> <s:iterator value="actionErrors"> <font color="red"><p id="message" class="errorMessage" ><s:property escape="false" /></p></font> </s:iterator> </s:if>
Sai Prasad
What happens is the page is reloaded again and this method i called twice.
Sai Prasad
This is same with onunload also
Sai Prasad
+1  A: 

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.

serioys sam
+1  A: 

I have found the jQuery dialog very easy to create popup's. This prevents the browser from blocking "real" popups, and the issues you described here.

GvS
A: 
<html>
<script type="text/javascript">
    function ConfirmClose()
    {
       if ((event.clientY < 0) ||(event.altKey) ||(event.ctrlKey)||((event.clientY < 129) && (event.clientY>107)))
        {
//event.altKey When press Alt +F4
//event.ctrlKey When press Ctrl +F4
//event.clientY 107 or 129 is  Alt F4 postion on window screen it may change base on screen resolution
alert('window closing');
        }
    }
</script>

<body topmargin='0'  onbeforeunload="ConfirmClose()">
</body>
 </html>
Rama Rao