window.opener Issue with Firefox

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Stefan Sch?rmeli

    #1

    window.opener Issue with Firefox

    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="+pop upY;

    winpops=window. open(url,"popup ","width=" + width + ",height=" +
    height + "," + pos + ",scrollbars=ye s,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 acceptPathAndCl ose(path,formna me,field) {
    form_h = eval("opener." + formname + "." + field);
    form_h.value = path;
    self.close();
    }

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

    Greets
    Stefan
  • Martin Honnen

    #2
    Re: window.opener Issue with Firefox



    Stefan Sch?rmeli wrote:

    [color=blue]
    > function acceptPathAndCl ose(path,formna me,field) {
    > form_h = eval("opener." + formname + "." + field);
    > form_h.value = path;
    > self.close();
    > }
    >
    > Firefox spams its JavaScript console with "opener.bla bla got no
    > properties" and just does nothing.[/color]

    You need to learn the proper way to address form elements:
    windowObject.do cument.forms.fo rmName
    or
    windowObject.do cument.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/

    Comment

    • Grant Wagner

      #3
      Re: window.opener Issue with Firefox

      Martin Honnen wrote:
      [color=blue]
      > Stefan Sch?rmeli wrote:
      >[color=green]
      > > function acceptPathAndCl ose(path,formna me,field) {
      > > form_h = eval("opener." + formname + "." + field);
      > > form_h.value = path;
      > > self.close();
      > > }
      > >
      > > Firefox spams its JavaScript console with "opener.bla bla got no
      > > properties" and just does nothing.[/color]
      >
      > You need to learn the proper way to address form elements:
      > windowObject.do cument.forms.fo rmName
      > or
      > windowObject.do cument.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.[/color]

      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.someFunc tionInOpener(fo rmname, field, text, value);

      Then in the opener window you'd have:

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

      Untested.

      --
      Grant Wagner <gwagner@agrico reunited.com>
      comp.lang.javas cript FAQ - http://jibbering.com/faq

      Comment

      Working...