views:

260

answers:

3

While developing a firefox extension, I create a wizard window from overlay.js using:

this.wizard = window.openDialog("chrome://firenow/content/wizard.xul", "","chrome, dialog, modal, resizable=no", params);
this.wizard.focus();

How can I close the wizard from overlay.js? I should call its cancel() function but I can't get it working!

+1  A: 

this.wizard would be a nsIDOMWindow object, but also implements the methods on nsIDOMWindowInternal, so you should be able to just call this.wizzard.close()

sdwilsh
sorry, it does not work
Giancarlo
I'd have to see the XUL of wizard.xul then to try and figure out what is going on.
sdwilsh
A: 

You can write your own hide function that does something to the extent of this.

wizard.style.display = 'none';

If you're paranoid, you can also remove all the child nodes of wizard in addition to hiding it.

Hope this helps! =)

wai
That's wrong. You don't close the wizard window, which keeps the associated resources in memory. The answer by sdwilsh is a better one.
Nickolay
@Nickolay: Hello. Thank you for your criticism. =) I am aware that my answer might be wrong. I only wrote in my answer after seeing sdwilsh's answer and the related comments. I was just trying to suggest different things. Now you might be more qualified than me to answer this question, but I think removing all child nodes and closing the window is similar as far as memory is concerned. If it was different, how much is the difference?
wai
@Nickolay: Sorry for the barrage of comments. Commenting again because this won't fit above. From the looks of his code, wizard is most likely a singleton object. How much memory can he leak? An interesting side effect of using this method is that we'll get to keep the 'wizard' node which means we can do more things to it later without having to pop the window front. It would also save us from headaches such as 'undefined' or 'null' because it got closed and save us from making a window.open call everytime we needed to change things. Once again, thank you for your time! =) Much appreciated!
wai
@wai: I don't know how much it will leak. I do know it's a window, which is a pretty heavy-weight object.Unfortunately, wizard is not a singleton - opening another wizard (even if overwriting the "this.wizard" reference) will create a new window without closing the old one.I didn't mean to pick on you, I just didn't like that a workaround was marked as "The answer" without a comment that it's a workaround.
Nickolay
PS. Comment discussions on SO are hard - I'm not notified about your replies and I'm forced to type replies in a 60x4 box. I suggest asking further questions in the mozilla.dev.* forums if you're interested.
Nickolay
@Nickolay: Oh no, that's perfectly alright. No hard feelings, man. =) I am sure we're all here to learn as well. I am just trying to make people realize there are some merits to the answer rather than flat out wrong. Thank you for taking the time anyway. =) Will investigate further on this matter.
wai
+1  A: 

You opened the wizard modally so your code stops running until the user cancels the wizard. In particular you don't get to find out the window object of the wizard until after it is closed, at which point focusing it will have no effect! If you really need to open the wizard modally you might still be able to close it, but you would have to add the code that closes the wizard in the wizard itself.

Neil