PDA

View Full Version : Referring to another window without


Topher
04-06-2004, 12:57 PM
Right, the problem is thus (I hope this makes sense)...

I have a script whereby I have a select box of options with a list of regular options that would normally be picked - but - on the odd occasion I will need to create another option, the details for which will need to be searched for.

So I have a button, which onClick brings up a search page in a pop-up window and when you click one of the search results it creates a new option in the select box of the previous window - or should.

Problem is I don't know how to refer to the previous window, parent.document.etc... doesn't seem to work, as I thought, as the pop-up window is not a child element of the window itself. The window unfortunately will have been opened from scratch so it won't have a name.

Anyone know a fix for this? Either to name a window that's already open or another solution?

The code to open the window is a normal window.open code:

function player_up(url,player) {

window.open(url,player,'width=500,height=250,left=15,top=15,location=no,menubar=no,resizable=no,scro llbars=yes,status=no,toolbar=no,fullscreen=no');

} // End of function
Like I said, hope I've made sense there, I'm not the best at explaining things, but I don't think posting lines of code would help in this instance.

eRad
04-06-2004, 01:22 PM
Any windows opened do become the child windows of that page. You can refer to them using window.opener.

You can then refer to and modify all elements of the parent window from the child window using opener.variablename, opener.formname.fieldname, etc.

What you'd probably want is to set a certain value and then close/refresh the child window.

The other thing you can do, if you have any experience with serverside scripting, is set the 'optional' fields on the parent that depend child windows to appear based on conditions. the child windows determine the condition as true/false. then whenever the user opens a child window it will set those conditions, refresh its parent, and close itself.

Topher
04-06-2004, 06:43 PM
Ah I didn't realise about the opener thing... Ta very much. :)