window.opener Issue with Firefox

S

Stefan Sch?rmeli

I already read about several problems using firefox and the
window.opener property. But obviously it didn't help out. So here is
my problem:

I got a "Search..." link which opens a new window with an FTP-browser.

function popup(url,width,height){
var popupX = (screen.width/2)-(width/2);
var popupY = (screen.height/2)-(height/2);
var pos = "left="+popupX+",top="+popupY;

winpops=window.open(url,"popup","width=" + width + ",height=" +
height + "," + pos + ",scrollbars=yes,toolbar=yes");
}

this code opens my popup. Now, the user browses his FTP and selects
some kind of folder or file. This value is automatically saved into a
readonly input form. To accept the selected path, the user got a form
button, which saves the path to the parent form (window.opener) and
closes the FTP-browser.

function acceptPathAndClose(path,formname,field) {
form_h = eval("opener." + formname + "." + field);
form_h.value = path;
self.close();
}

Firefox spams its JavaScript console with "opener.blabla got no
properties" and just does nothing. Internet Explorer executes this
code as expected. How can i solve this annoying problem?

Greets
Stefan
 
M

Martin Honnen

Stefan Sch?rmeli wrote:

function acceptPathAndClose(path,formname,field) {
form_h = eval("opener." + formname + "." + field);
form_h.value = path;
self.close();
}

Firefox spams its JavaScript console with "opener.blabla got no
properties" and just does nothing.

You need to learn the proper way to address form elements:
windowObject.document.forms.formName
or
windowObject.document.forms['formName']
so in the above function you want
var form_h = opener.document.forms[formname].elements[field];
that way the form and the control are addressed properly in all browsers
starting from Netscape 3.
 
G

Grant Wagner

Martin said:
Stefan said:
function acceptPathAndClose(path,formname,field) {
form_h = eval("opener." + formname + "." + field);
form_h.value = path;
self.close();
}

Firefox spams its JavaScript console with "opener.blabla got no
properties" and just does nothing.

You need to learn the proper way to address form elements:
windowObject.document.forms.formName
or
windowObject.document.forms['formName']
so in the above function you want
var form_h = opener.document.forms[formname].elements[field];
that way the form and the control are addressed properly in all browsers
starting from Netscape 3.

Although

var form_h = opener.document.forms[formname].elements[field];

may fail in Internet Explorer if you attempt to do anything other than
access the form control's value. For example, if -field- is a <select> and
you attempt to add or remove(?) Option() objects from it via a new window,
you will not be able to.

For example:

var form_h = opener.document.forms[formname].elements[field];
form_h[form_h.length] = new Option(text, value);

would fail in Internet Explorer with "access denied". The way to achieve the
same result is with:

opener.someFunctionInOpener(formname, field, text, value);

Then in the opener window you'd have:

function someFunctionInOpener(fn, f, t, v) {
var form_h = document.forms[fn].elements[f];
form_h[form_h.length] = new Option(t, v);
}

Untested.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,905
Latest member
Kristy_Poole

Latest Threads

Top