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
jjb
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
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
It still returns null. :-(
'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
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
>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.
> 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.
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