Click to See Complete Forum and Search --> : Possible to access different windows with JS?
Berra_la
02-04-2003, 07:26 AM
Hi!
I have a form on the main site (in some frames) and want to access and change the contents of it from links in another window (opened from the main site). Is this possible? If not, is there any way I can get around this problem? (using only javascript and html)
thanks,
- Berra
You should be able to use window.opener. It might be a bit tricky with frames. Try something like window.opener.top.framename.formname.inputname.value = "yourvalue"; changing the items in bold to your names.
gil davis
02-04-2003, 07:42 AM
Yes, as long as the pages are on the same domain.
If each page gives its window a unique name (window.name="whatever"), you can create a pointer to that window in another page using "window.open()":
var myWin = window.open("","whatever");
Then you can use that pointer to access the window and do what you need to do.
Note that if there is no window with that name ( e.g.: if the user closed it), this will open an empty window. There is no way to just test for a window with a certain name.
If there is an existing relationship (e.g.: opener to child), you can take advantage of that as well. You have not given enough information to tell if there is such a possibility.
Berra_la
02-04-2003, 08:05 AM
For some reason the .top.framename. (.top.page. in my case) don't seem to work. But since the frame with the form is the same that opened the new window I don't need it anyway. :)
It works now, thanks!
I feel a bit silly now. I read about the opener command, and dismissed it... doh!
- Berra
Originally posted by Berra_la
For some reason the .top.framename. (.top.page. in my case) don't seem to work.Yeah, I wasn't sure if top.framename worked with window.opener. Guess it doesn't. :) Glad you got it working.