Communication between browser windows?

J

J Krugman

I need guidance on implementing the following functionality in
JavaScript:

User clicks on a link (or button) in browser window A that brings
up a separate browser popup window B featuring a list/table of 500+
clickable items; clicking on any one of these items causes it (or
rather its label string) to be added to the contents of a textarea
field in the original page A, perhaps after checking that it has
not been added already.

The document in window B must somehow know about the document in
window A, and the script must behave appropriately (i.e. do nothing)
if the document in window A disappears for some reason (e.g. user's
navigation, window closing, etc.) and the user clicks on an item
in window B.

Any advice on implementing this would be much appreciated.

TIA,

jill
 
M

Mick White

J said:
I need guidance on implementing the following functionality in
JavaScript:

User clicks on a link (or button) in browser window A that brings
up a separate browser popup window B featuring a list/table of 500+
clickable items; clicking on any one of these items causes it (or
rather its label string) to be added to the contents of a textarea
field in the original page A, perhaps after checking that it has
not been added already.

The document in window B must somehow know about the document in
window A, and the script must behave appropriately (i.e. do nothing)
if the document in window A disappears for some reason (e.g. user's
navigation, window closing, etc.) and the user clicks on an item
in window B.

if(opener){ //window A is available }}

or better yet, look for a known object in window A.

if(opener.document.forms["formName"].elements["elementName"])

Mick
 
T

Thomas 'PointedEars' Lahn

J said:
I need guidance on implementing the following functionality in
JavaScript:

User clicks on a link (or button) in browser window A that brings
up a separate browser popup window B featuring a list/table of 500+
clickable items; clicking on any one of these items causes it (or
rather its label string) to be added to the contents of a textarea
field in the original page A, perhaps after checking that it has
not been added already.

The document in window B must somehow know about the document in
window A, and the script must behave appropriately (i.e. do nothing)
if the document in window A disappears for some reason (e.g. user's
navigation, window closing, etc.) and the user clicks on an item
in window B.

Any advice on implementing this would be much appreciated.

In the "onclick" event handler of the triggering element in browser
window A call window.open(). You may want to cancel the event by
returning `false' to the handler. In the "onchange" event handler of
the triggering "select" element or (better) in the "onclick" event
handler of the triggering "add" button in window B, read the value
or text of the currently selected item and append it to the "value"
property of the (HTML)TextArea(Element) object in the Window referenced
by the "opener" property of the current Window/global object, possibly
delimited with newline ("\n"). You need to check if "opener" is a valid
object reference and if it has not been closed and if has such an
(HTML)TextArea(Element) object before.

Checking that the value has not been added already is somewhat difficult
as you need to find a way to tell one entry from the other, perhaps
using Regular Expression matching. Probably a (HTML)Select(Element)
object would do better than a (HTML)TextArea(Element) object. How you
add options to a "select" element should be in the FAQ or available via
Google Groups search. You could instead disable the currently selected
option in window B after its value/text has been added to the "textarea"
element in window A but I doubt this can be implemented cross-browser.

Don't forget to provide a server-side alternative for users who have
no client-side script support available.


HTH

PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top