Need detection of window close

4 views
Skip to first unread message

Nico

unread,
Dec 15, 2009, 12:19:45 PM12/15/09
to mozilla-labs-prism
Hi,

We are interested in using prism for a web-based modeling tool. One
missing feature is the detection of window close in javascript and
this is a show-stopper for us, because we have to warn the user, in
cases he hasn't saved the changes.

On

https://wiki.mozilla.org/Prism#Wishlist

it is listed that the detection of window close in javascript is on
the wishlist. is it still correct or is it already implemented? When
will it be available? Does anyone already has a solution for this?

We already have a xulrunner-based client for our modeling tool, but we
would now like to use prism features in the next release. In the old
client, we simply added the following lines of code into the xul page
the modeling tool is loaded in:

function WindowIsClosing()
{
_getBrowser().contentWindow.close();
return false;
}
function _getBrowser() {
return document.getElementById("browser_content");
}

I've added it to the webrunner.xul file, but it doesn't work in prism.
Does anyone know why?

Thanks in advance.

Cheers,

Nico

Jeromatron

unread,
Dec 15, 2009, 2:16:44 PM12/15/09
to mozilla-labs-prism
I would look here:

https://developer.mozilla.org/en/Prism

for current prism dev documentation instead of the wiki. The wiki is
very much out of date... the above link is current.

Check out the link to Scripting on that page. It lists some hooks you
can key in to like the shutdown function. It sounds like that would
be easier than messing with the xulrunner itself, but that may not be
sufficient for what you need.

Hope that helps...

Jeremy

Nico

unread,
Dec 16, 2009, 10:35:51 AM12/16/09
to mozilla-labs-prism
Hi Jeremy,

thanks for your quick reply. I don't think the scripting API will be
sufficient, because as far as I understood it, the shutdown callback
runs when the application shuts down. but in our application you
usually open several windows and we need to check for changes,
whenever one of the windows is closed.

but I made some progress. before, I forgot to call my WindowIsClosing
() method in the onclose callback of the window element in
webrunner.xul:

onclose="return WindowIsClosing() && WebRunner.tryClose();"

now it works, but unfortunately I cannot close the main window anymore
(the first window that is opened when starting prism). Any hints how I
can fix this?

cheers,

Nico

Nico

unread,
Dec 17, 2009, 7:19:26 AM12/17/09
to mozilla-labs-prism
Hi,

I've played around a bit. for testing I run the following code when in
the onclose callback:

var test = _getBrowser().contentWindow.close();
alert(test);

and found out the following situations:

1. Closing a window without the warning about unsaved changes:

_getBrowser().contentWindow.close() returns undefined


2. Closing a window with the warning and clicking on cancel:

_getBrowser().contentWindow.close() returns undefined


3. Closing a window with the warning and clicking on ok:

for some reason the alert box is not shown


can someone explain to me how to handle the warning dialog and
distinguishing between a click on Ok and Cancel?

Cheers,

Nico

Nico

unread,
Jan 12, 2010, 7:46:51 AM1/12/10
to mozilla-labs-prism
I think I've found a bug in Prism's webrunner.js file. Following
situation:

I've started Prism that loads a web page.
On this web page, I double-click on an icon that calls window.open()
to load another URL in a new window.
The new window opens.
I click on the "X" of the new window to close it.

In this situation the variable this._xulWindow in WebRunner.tryClose()
is null.

tryClose : function()
{
var contentViewer = this._xulWindow.docShell.contentViewer;
if (contentViewer && !contentViewer.permitUnload()) {
return false;
} else {
return true;
}
},

This is not the case for the first window. Any suggestions how to fix
that?

Here is the code that initializes the variable:

this._xulWindow = window.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShellTreeItem)
.treeOwner
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIXULWindow);

Thanks in advance.

Cheers,

Nico

Matthew Gertner

unread,
Jan 15, 2010, 8:21:58 AM1/15/10
to mozilla-l...@googlegroups.com
I'm not sure what that code is supposed to do, but perhaps the DOM
event "onbeforeunload" will do what you want.

> --
>
> You received this message because you are subscribed to the Google Groups "mozilla-labs-prism" group.
> To post to this group, send email to mozilla-l...@googlegroups.com.
> To unsubscribe from this group, send email to mozilla-labs-pr...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mozilla-labs-prism?hl=en.
>
>
>

Jason Miller

unread,
Jan 15, 2010, 11:18:04 AM1/15/10
to mozilla-l...@googlegroups.com
Good point, I have noted that onbeforeunload does work when closing the window or quitting the app.


On Fri, Jan 15, 2010 at 8:21 AM, Matthew Gertner <matthew...@gmail.com> wrote:
I'm not sure what that code is supposed to do, but perhaps the DOM
event "onbeforeunload" will do what you want.
Reply all
Reply to author
Forward
0 new messages