window.opener Issue with Firefox

Discussion in 'Javascript' started by Stefan Sch?rmeli, Oct 28, 2004.

  1. 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
    Stefan Sch?rmeli, Oct 28, 2004
    #1
    1. Advertising

  2. 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.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
    Martin Honnen, Oct 28, 2004
    #2
    1. Advertising

  3. Stefan Sch?rmeli

    Grant Wagner Guest

    Martin Honnen wrote:

    > 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.


    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.

    --
    Grant Wagner <>
    comp.lang.javascript FAQ - http://jibbering.com/faq
    Grant Wagner, Oct 28, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Bewley via DotNetMonster.com

    window to window communication (window.opener)

    Andrew Bewley via DotNetMonster.com, Feb 3, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    1,016
    Andrew Bewley via DotNetMonster.com
    Feb 3, 2005
  2. Urs Gubler
    Replies:
    0
    Views:
    136
    Urs Gubler
    Jul 2, 2003
  3. atlas
    Replies:
    1
    Views:
    126
    Martin Honnen
    Sep 7, 2005
  4. window.opener, form.opener?

    , Jul 14, 2006, in forum: Javascript
    Replies:
    5
    Views:
    267
  5. Asterix

    window.opener with FireFox Issue

    Asterix, Aug 8, 2008, in forum: Javascript
    Replies:
    3
    Views:
    140
    Thomas 'PointedEars' Lahn
    Aug 9, 2008
Loading...

Share This Page