Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Existing Window handle?

Status
Not open for further replies.

cerb

Programmer
Oct 15, 2002
10
GB
Hello fellow programmers.
I am trying to write a small .js script as part of a complicated perl script.
[I am a perl programmer, so sorry if the question sounds easy, but I looked up for hours to different examples without any help!]

What i would like to do is to update the value of a text area with the result of some processing (appending some text to it).
Ok I know it can be easily done with:
document.nameform.Text.value += related_text;

The problem is that the text area I want to write into is NOT in the current "document" (i.e. not in the current browser window).
I have the original textarea in one window, and the update button & related_text created in a totally separate window (which is generated as part of the script after various other steps). The function is basically a search which needs to go through a series of steps (like a wizard), output the result in a separate window where the user can still modify it, and then when the user presses the OK final button should bring the final text (which is agreed on) in the ORIGINAL window (from which everything had started).

Now, I know that you can pass variables from one window to another, doing something similar to this example:

function writeConsole(content) {
top.consoleRef=window.open('','myconsole',
'width=350,height=250'
+',menubar=0'
+',toolbar=1'
+',status=0'
+',scrollbars=1'
+',resizable=1')
top.consoleRef.document.writeln(
'<html><head><title>Console</title></head>'
+'<body bgcolor=white onLoad=&quot;self.focus()&quot;>'
+content
+'</body></html>'
)
top.consoleRef.document.close()
}

But my problem is:
in this example you GENERATE the window in which you then go and write to, so you HAVE the handle for this window (top.consoleRef) to go and write to it afterwards.
What I need to do is to GET an handle for an &quot;existing&quot; window (not generated by the script itself), so I can write to it.

Of the first window (with the textarea to which i want to input results), I CAN GET parameters of as I CAN WRITE to it some Javascript. So I can create names, objects etc.
I tried as an example to put in this first window something like:
window.name=&quot;cer&quot;;

and then write to the textarea from the second window as:
cer.Text.value += related_text;

but this does get an error (cer not existing).

I assume that from the second window I would need to do a &quot;search&quot; trough all the existing windows and find the one with the specific attribute and then find the handle for it (this is what you would do in c...), but I have no idea of how to do this in Javascript, or if there is any easier way to create a simple communication channel between two windows

Basically I want to pass a string from one window textarea, to a separate window textarea, with the target textarea being in the ORIGINAL window. I.e. I would like to communicate from one window to an existing one (not created within the .js itself; but ALREADY EXISTING; I need to find out the handle for this existing window).

It sounds complicated, but I am sure you JS gurus can help...

[ BTW, I &quot;could&quot; create a newpage addressing to the original URL just to get the handle and then write to this handle, but the original page has many fields and the user might have left the form incomplete while using this function, so relading on a separate window would bring up only empty fields, even if in that case I would have the handle and could write to the textarea in the original window...]
 
cerb,
javascript can only access windows it creates, and only within the scope of that page - meaning if window A creates window B, window A can reference window B so long as window A isn't refreshed in the meantime.

so...if you open window X on its own, then open window Y on its own, the two cannot communicate.

hope this helps!

and if anyone knows otherwise, please enlighten me...I'd love to be able to do this too!

:)

 
That's a pity! It really limits a lot what you can do....
I might rethink to the way I implemented the program... and use multiple (hidden) layers and try to communicate from one layer to another then...

But if anyone has a solution (for example interfacing with some simple Java code which I am sure is able to do this), please post here!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top