incubator-adffaces-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christoph Lassner <Christoph.Lass...@esg.de>
Subject Re: Closing dialog with alt-f4
Date Thu, 21 Sep 2006 08:09:29 GMT
Hello Martin,

there is a possibility to control this, because an onUnload JavaScript
action is fired in the dialog window at closing. The way to control such an
action would be to add an onUnload property to your body tag of the pages
in the dialog window that calls a JavaScript function in the parent window.
This function has to check wether the dialog has been closed or only
another page has been loaded and then do the necessary actions.

Sounds difficult, but is very easy. Here's a simple example:


parent.html:
<HTML>
<HEAD>

<TITLE>Controltest</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
var dialog  = null;

function checkIfClosed()
      {
      alert("Checking if child is closed...");
      if(dialog != null)
            {
            alert("Child has been opened!");
            if(dialog.closed == true)
                  {     dialogClosed();   }
            else
                  {     alert("... and not been closed yet!");    }
            }
      else
            {
            alert("Child has never been open!");
            }
      }

function dialogClosed()
      {
      alert("Hey dude, you at least gotta fill out our great dialog!");
      }

function openDialog()
      {
      dialog      = window.open("child1.html", "dialog", "");
      }
//-->
</SCRIPT>

</HEAD>
<BODY>

<A HREF="Javascript: openDialog();">Open Dialog</A>
<A HREF="Javascript: checkIfClosed();">CheckIfClosed</A>

</BODY>
</HTML>


child1.html:
<HTML>
<HEAD>

<TITLE>Child 1</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
function callParent()
      {
      alert("Calling parent...");
      window.opener.checkIfClosed();
      alert("Ready!");
      }

//-->
</SCRIPT>

</HEAD>
<BODY onUnload="window.opener.setTimeout('checkIfClosed();',0);">

<A HREF="child2.html">Goto child 2</A>
<A HREF="Javascript: callParent();">callParent()</A>

</BODY>
</HTML>


and child2.html:
<HTML>
<HEAD>

<TITLE>Child 1</TITLE>
<SCRIPT LANGUAGE="JavaScript">
<!--
function callParent()
      {
      alert("Calling parent...");
      window.opener.checkIfClosed();
      alert("Ready!");
      }

//-->
</SCRIPT>

</HEAD>
<BODY onUnload="window.opener.setTimeout('checkIfClosed();',0);">

<A HREF="child1.html">Goto child 1</A>
<A HREF="Javascript: callParent();">callParent()</A>

</BODY>
</HTML>



The function callParent() in the two childPages is unnecessary and only
there to show how it works (calling the parent window). The
window.opener.setTimeout(...) is necessary, because at a direct call of the
function checkIfClosed() on unloading the child window.closed property
would still return false, so this is a little workaround.

Have fun with these scripts and mail if you encounter problems!
Chris



"Adam Winer" <awiner@gmail.com> schrieb am 20.09.2006 18:59:52:

> No, we don't currently address this;  you get no events
> when this happens.
>
> -- Adam
>
>
> On 9/20/06, Martin Koci <Martin.Koci@aura.cz> wrote:
> >
> > Hello,
> >
> > there is commmon problem with web application that we cannot register a
> > listener to a "closing window" event.
> >
> > Have trinidad a solution for this - call a returnListener if user
closes
> > dialog with alt-f4 or with click at cross in right top corner?
> >
> > Thanks,
> >
> > Martin
> >
> >
> >
> >
> >


Mime
View raw message