Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to give focus to a popup window ?

640 views
Skip to first unread message

Marie Kesquetta

unread,
Feb 5, 2007, 8:12:55 AM2/5/07
to

all right, the short answer would be "window.focus()", but it does not work in my case:

if i do:

var w=open("chrome://xxxx","mywindow","chrome");
setTimeout(function(w) { w.focus() },0,w);

this works just fine, whether the window is already opened or not, it gets the focus.

but i need to pass my window some arguments. the only way i found is to use the openWindow method of the nsIWindowWatcher
interface.

the popup window is correctly opened the first time, but if the window is already there and behind, the focus() method
simply does not work (without any exception). setting the activeWindow field of the window watcher does work better.

any idea anyone ?

eric...@yahoo.com

unread,
Feb 5, 2007, 10:48:57 AM2/5/07
to dev-ext...@lists.mozilla.org
You can pass parameters to the window as the final argument in the open() function; e.g.,

var params = {a:"123", b:"456", c:true, d:false};

window.open("chrome://myext/chrome/mywin.xul", "",
"chrome, dialog, modal, resizable=yes", params).focus();

In mywin.xul, you can access the parameters this way:

window.arguments[0].a; // 123
window.arguments[0].b; // 456
window.arguments[0].c; // true
window.arguments[0].d; // false

if i do:

any idea anyone ?
_______________________________________________
dev-extensions mailing list
dev-ext...@lists.mozilla.org
https://lists.mozilla.org/listinfo/dev-extensions

Marie Kesquetta

unread,
Feb 5, 2007, 11:29:16 AM2/5/07
to

Thanks for your reply.

Actually, if i do what you describe, window.arguments is undefined from mywin.xul.

>From http://www.xulplanet.com/references/xpcomref/ifaces/nsIDOMWindowInternal.html#method_open , i can see that
there is no extra argument for the open() method, contrarily to openDialog()
http://www.xulplanet.com/references/xpcomref/ifaces/nsIDOMWindowInternal.html#method_openDialog , or the
openWindow method of nsIWindowWatcher http://www.xulplanet.com/references/xpcomref/ifaces/nsIWindowWatcher.html#method_openWindow

Neil

unread,
Feb 5, 2007, 11:30:37 AM2/5/07
to
eric...@yahoo.com wrote:

>You can pass parameters to the window as the final argument in the open() function; e.g.,
>
>

You're thinking of openDialog.

--
Warning: May contain traces of nuts.

eric...@yahoo.com

unread,
Feb 5, 2007, 1:38:37 PM2/5/07
to dev-extensions
Well, let me ask a dumb question... why not use openDialog() or openWindow()?

----- Original Message ----
From: Marie Kesquetta <0LOgcN8f...@spambox.us>
To: dev-ext...@lists.mozilla.org
Sent: Monday, February 5, 2007 11:29:16 AM
Subject: Re: How to give focus to a popup window ?


Thanks for your reply.

Actually, if i do what you describe, window.arguments is undefined from mywin.xul.

eric...@yahoo.com wrote:
> You can pass parameters to the window as the final argument in the open() function; e.g.,
>

Eric H. Jung

unread,
Feb 5, 2007, 1:51:00 PM2/5/07
to dev-extensions
...answering my own question: because it's a popup. You could instead send it custom data using an observer in your XUL and publishing a custom notification in the setTimeout() callback.
http://www.xulplanet.com/tutorials/mozsdk/observerserv.php
Let me know if you need an example.

Marie Kesquetta

unread,
Feb 5, 2007, 5:54:30 PM2/5/07
to

yes, i can imagine many workarounds of that kind but this would make my design more complex for solving something that
should be a detail. I really through there would be an easy way to give focus to whatever window when you are in chrome.

i will live with the following: opening my first popup using window.open as i don't need arguments there, then for other popups
use window watcher's openWindow() using the 'dependent' window option. that makes the child popups to open always in front of
the first one but this is acceptable in my case, even if not perfect.

thanks for your suggestions.

Eric H. Jung wrote:
> ...answering my own question: because it's a popup. You could instead send it custom data using an observer in your XUL and publishing a custom notification in the setTimeout() callback.
> http://www.xulplanet.com/tutorials/mozsdk/observerserv.php
> Let me know if you need an example.
>

> From: "eric...@yahoo.com" <eric...@yahoo.com>
> Well, let me ask a dumb question... why not use openDialog() or openWindow()?
>

> From: Marie Kesquetta <0LOgcN8f...@spambox.us>
> Actually, if i do what you describe, window.arguments is undefined from mywin.xul.
>
>>From http://www.xulplanet.com/references/xpcomref/ifaces/nsIDOMWindowInternal.html#method_open , i can see
> that
> there is no extra argument for the open() method, contrarily to openDialog()
> http://www.xulplanet.com/references/xpcomref/ifaces/nsIDOMWindowInternal.html#method_openDialog , or the
> openWindow method of nsIWindowWatcher http://www.xulplanet.com/references/xpcomref/ifaces/nsIWindowWatcher.html#method_openWindow
>
> eric...@yahoo.com wrote:
>> You can pass parameters to the window as the final argument in the open() function; e.g.,
>>
>> var params = {a:"123", b:"456", c:true, d:false};
>>
>> window.open("chrome://myext/chrome/mywin.xul", "",
>> "chrome, dialog, modal, resizable=yes", params).focus();
>>
>> In mywin.xul, you can access the
> parameters this way:
>> window.arguments[0].a; // 123
>> window.arguments[0].b; // 456
>> window.arguments[0].c; // true
>> window.arguments[0].d; // false
>>

eric...@yahoo.com

unread,
Feb 5, 2007, 7:56:16 PM2/5/07
to dev-ext...@lists.mozilla.org
I thought the problem was getting arguments to the window, not focusing it.


----- Original Message ----
From: Marie Kesquetta <0LOgcN8f...@spambox.us>
To: dev-ext...@lists.mozilla.org

thanks for your suggestions.

Marie Kesquetta

unread,
Feb 6, 2007, 2:43:50 AM2/6/07
to

The problem was to have both at the same time.

Christian Metzler

unread,
Feb 6, 2007, 4:28:35 AM2/6/07
to dev-ext...@lists.mozilla.org
Hi,

does anyone have an idea how I can let my extension know, when a mail
has been sent correctly? It should not matter, if this event happened
after a "send now" or a "send later" operation. I just need to know,
when the sending of any message has been finished.
Thank you!

Kind regards,
Coco


Nickolay Ponomarev

unread,
Feb 6, 2007, 8:15:35 AM2/6/07
to Marie Kesquetta, dev-ext...@lists.mozilla.org

So first of all (re-)read
http://developer.mozilla.org/en/docs/Working_with_windows_in_chrome_code

1. If you want to open new window and pass parameters to it use either
openDialog or, if you're an XPCOM component, the window watcher. You
don't need to (and shouldn't) focus the opened window manually using
.focus() in this case.
2. If you want to reactivate an existing window, use win.focus(). You
can save the reference when you open window and use it to focus the
window. Alternatively you can retrieve the reference using the window
mediator.
3. If you want to pass parameters to a window that is already open,
you can do something like this:
a) define function send(arguments) in the popup window
b) when you want to pass arguments to an already opened window, call
win.send(args)
c) you may want to call send(window.arguments) in onload handler in the popup.

Nickolay

Nickolay Ponomarev

unread,
Feb 6, 2007, 8:37:01 AM2/6/07
to Marie Kesquetta, dev-ext...@lists.mozilla.org
Oh, forgot to mention that on certain platforms (e.g. Linux at least
in earlier versions of Gecko) .focus() doesn't work and I don't know a
way around this.

Nickolay

On 2/6/07, Nickolay Ponomarev <asqu...@gmail.com> wrote:
> On 2/5/07, Marie Kesquetta <0LOgcN8f...@spambox.us> wrote:
> >

Marie Kesquetta

unread,
Feb 6, 2007, 11:26:25 AM2/6/07
to

All right, that must be the point. I develop on Linux.

Thanks for your explanations.

Neil

unread,
Feb 6, 2007, 11:28:47 AM2/6/07
to
Nickolay Ponomarev wrote:

> Oh, forgot to mention that on certain platforms (e.g. Linux at least
> in earlier versions of Gecko) .focus() doesn't work and I don't know a
> way around this.

Well, it depends on the behaviour of your windowmanager, and whether
you're trying to focus a content window in a build with L. David Baron's
first patch for his focus-stealing problem.

Nickolay Ponomarev

unread,
Feb 6, 2007, 11:37:59 AM2/6/07
to Neil, dev-ext...@lists.mozilla.org
Last time I checked (long time ago, admittedly) there was the issue
where raising a *chrome* window via .focus() plain didn't work on
metacity.

I found a bug in bugzilla where it was claimed this was what the Linux
users expect. I think it's dumb, like many other mozilla-on-linux
pecularities, but as long as I'm not forced to use Linux, I don't care
very much.

Nickolay

0 new messages