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

accessing a dialog via javascript

1 view
Skip to first unread message

Red_Se...@hotmail.de

unread,
Sep 30, 2008, 10:31:28 AM9/30/08
to
Hello,

I open a dialog through javascript and the window.openDialog()
function. Afterwards, I want to add a description child node into it,
however document.getElementById("donothing") always returns null, even
though I triple-checked the id-tag by now.

I tried to do it in a different way, ergo by clicking on the button a
function is called which only opens the dialog and the rest of the
function gets called via unload. When I tried it this way it seemed to
work, but gMsgCompose, which is used in the rest of the function, is
unknown then. Probably because the dialog is no overlay... =/

So, any ideas? Or even better code snippets?

Greetings,
Serratia

John J. Barton

unread,
Sep 30, 2008, 10:53:32 AM9/30/08
to
Red_Se...@hotmail.de wrote:
> Hello,
>
> I open a dialog through javascript and the window.openDialog()
> function. Afterwards, I want to add a description child node into it,
> however document.getElementById("donothing") always returns null, even
> though I triple-checked the id-tag by now.
>
I suggest you triple check the 'document' object. It's probably not what
you think.

jjb

Red_Se...@hotmail.de

unread,
Sep 30, 2008, 11:42:46 AM9/30/08
to
On 30 Sep., 16:53, "John J. Barton" <johnjbar...@johnjbarton.com>
wrote:

Hm... I thought that document is more-or-less the root element of the
DOM-tree...
Though I guess I also never inserted the dialog into the DOM-tree...
I'm a bit unsure on how to do that...

Greetings
Serratia

Arivald

unread,
Sep 30, 2008, 11:48:12 AM9/30/08
to
Red_Se...@hotmail.de pisze:

Every window, (dialog is a specialized window) have it own "global" Js
context, called (guess why ;-) ) "window".

To access different window, you need to find it's global context.
openDialog() returns this context;

Now, if you have your dialog context, try:

var myDialog = openDialog(...);
var element = myDialog.document.getElementById("donothing");

But remember: both windows have different contexts! Objects from one
window does not exists in another one!


And go to http://developer.mozilla.org/ and read a lot...


--
Arivald

Red_Se...@hotmail.de

unread,
Sep 30, 2008, 12:02:02 PM9/30/08
to
On 30 Sep., 17:48, Arivald <arivald_@AT_interia_DOT_pl> wrote:
> Red_Serra...@hotmail.de pisze:
> And go tohttp://developer.mozilla.org/and read a lot...
>
> --
> Arivald

It still returns null. :-(

John J. Barton

unread,
Sep 30, 2008, 12:11:24 PM9/30/08
to
Red_Se...@hotmail.de wrote:
> On 30 Sep., 16:53, "John J. Barton" <johnjbar...@johnjbarton.com>
> wrote:
>> Red_Serra...@hotmail.de wrote:
>>> Hello,
>>> I open a dialog through javascript and the window.openDialog()
>>> function. Afterwards, I want to add a description child node into it,
>>> however document.getElementById("donothing") always returns null, even
>>> though I triple-checked the id-tag by now.
>> I suggest you triple check the 'document' object. It's probably not what
>> you think.
>>
>> jjb
>
> Hm... I thought that document is more-or-less the root element of the
> DOM-tree...

'document' is bound to which 'window'? The dialog or the one that opened
the dialog?

If you print document.documentElement.innerHTML you can know for sure...

jjb

Gijs Kruitbosch

unread,
Sep 30, 2008, 1:00:08 PM9/30/08
to

Your earlier point about using the load event may be the right thing to do. I
*think* that when openDialog returns, the URL you gave it might not be loaded
yet. From what I can recall (apply salt as necessary) it loads about:blank
first, to stop your code from hanging when it may be waiting for network things
to complete. So, you need to use the onload event to make sure the document
which has that button actually loads before you try to get the element.

As other people said, the gWhatever things that you can use in your normal
window are not available in your window, at least not by definition. You can fix
this in at least 2 ways, that I know of:
1. By passing parameters. Read the MDC docs for more info on that:
http://developer.mozilla.org/En/DOM:window.openDialog . The window.arguments
variable then contains these extra parameters.
2. By using the window manager to find the handle for the calling window, and
get a hold of the object you want in that way.

However you do it, you need to make sure not to create memory leaks in this
manner. Always remove event listeners that you add before closing the dialog,
etc. etc.


Hope that helps,
Gijs

Neil

unread,
Sep 30, 2008, 1:03:13 PM9/30/08
to
Red_Se...@hotmail.de wrote:

>I open a dialog through javascript and the window.openDialog() function. Afterwards, I want to add a description child node into it
>

After what? If this is a modal dialog, then the calling script halts
until the window is closed, by which time it is too late to do anything
to it. Instead you have to pass parameters through openDialog and have
the dialog's script add the child node.

--
Warning: May contain traces of nuts.

Neil

unread,
Sep 30, 2008, 1:06:33 PM9/30/08
to
Gijs Kruitbosch wrote:

> 2. By using the window manager to find the handle for the calling
> window, and get a hold of the object you want in that way.

window.opener also works.

Red_Se...@hotmail.de

unread,
Oct 8, 2008, 11:14:24 AM10/8/08
to
On 30 Sep., 19:00, Gijs Kruitbosch <gijskruitbo...@gmail.com> wrote:
> >> And go tohttp://developer.mozilla.org/andread a lot...

>
> >> --
> >> Arivald
>
> > It still returns null. :-(
>
> Your earlier point about using the load event may be the right thing to do. I
> *think* that when openDialog returns, the URL you gave it might not be loaded
> yet. From what I can recall (apply salt as necessary) it loads about:blank
> first, to stop your code from hanging when it may be waiting for network things
> to complete. So, you need to use the onload event to make sure the document
> which has that button actually loads before you try to get the element.
>
> As other people said, the gWhatever things that you can use in your normal
> window are not available in your window, at least not by definition. You can fix
> this in at least 2 ways, that I know of:
> 1. By passing parameters. Read the MDC docs for more info on that:http://developer.mozilla.org/En/DOM:window.openDialog. The window.arguments

Thank you for your help (and everyone else as well of course).
I'm using thist first method via Parameters now. Not my preferred
method, but it is working, so thank you

0 new messages