Netscape DOM issue?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark Stafford

    Netscape DOM issue?

    I want to use a pop-up dialog for my intranet, but I'm missing
    something that keeps me from getting along with NS's browsers right
    now.

    I get an error to the effect of "opener.formNam e has no properties"

    The following JS is its own file included in caller.html and
    callee.html with this syntax <SCRIPT language="JavaS cript"
    src="pops.js"></SCRIPT>

    It works in current IE's on multiple platforms and in Apple's Safari.
    Any ideas about how I might work it for NS?

    Thanks,

    Mark

    // <pops.js>

    var DEBUGGING=false ;
    var myTarget=null;

    function popUp(argURL, argOBJ, argH, argW) {
    /* Useage example from caller.html:
    <FORM name="stockForm ">
    <INPUT name="txtA" type="text" id="txtA" value="" size="10" />
    <INPUT name="btnA" type="button" id="btnA"
    onClick="popUp( 'callee.html', this)" value="." /><BR />
    </FORM>
    */
    try {
    // default to 300x300, otherwise use options offered
    argH=(!argH || argH==0) ? 300 : argH;
    argW=(!argW || argW==0) ? 300 : argW;
    // establish error message in case something goes wrong
    var Err = new Error();
    Err.message="mc s.js popUp(" + argURL + ", " + argOBJ.name + ", " +
    argH + ", " + argW + ") error:\n\nmyTar get not established or window
    not opened";
    // set aside the name of the object which will be receiving the
    value chosen in the popUp window
    // presumes usage from naming as used above txtA and btnA
    myTarget=argOBJ .form.name+'.'+ 'txt'+argOBJ.na me.substr(3,
    argOBJ.name.len gth-3);
    if (DEBUGGING) alert('myTarget ='+myTarget);
    // open the popUp
    listWin=window. open(argURL, 'list', 'height='+argH+ ',
    width='+argW+', left =100, top=100, location=no, menubar=no,
    resizable=yes, scrollbars=yes, status=no, toolbar=no');
    // complain if it didn't work
    if (myTarget==null || !listWin) throw(Err);
    }
    catch (Err)
    { alert(Err.messa ge); }
    }

    function popDown(argVAL) {
    /* Useage example from callee.html:
    <A href="#" onClick="popDow n('AMZN')">AMZN </A>
    */
    try {
    // establish error message in case something goes wrong
    var Err = new Error();
    Err.message="mc s.js popDown("+argVA L+") error:\n\nmyTar get not set";
    var evalMe="opener. "+opener.myTarg et+".value="+"' "+argVAL+"' ";
    if (DEBUGGING) alert('evalMe=' +evalMe);
    eval(evalMe);
    // if myTarget != val then complain
    if (eval("opener." +opener.myTarge t+".value!="+"' "+argVAL+"' "))
    throw(Err);
    else window.close();
    }
    catch (Err)
    { alert(Err.messa ge); }
    }

    // </pops.js>
  • DU

    #2
    Re: Netscape DOM issue?

    Mark Stafford wrote:[color=blue]
    > I want to use a pop-up dialog for my intranet, but I'm missing
    > something that keeps me from getting along with NS's browsers right
    > now.
    >
    > I get an error to the effect of "opener.formNam e has no properties"[/color]

    opener is a window object reference. formName is a form name attribute.
    You need the document node in between. So:

    opener.document .formName should reference appropriately the form.
    [color=blue]
    >
    > The following JS is its own file included in caller.html and
    > callee.html with this syntax <SCRIPT language="JavaS cript"
    > src="pops.js"></SCRIPT>[/color]

    Validate your markup. Doing so will avoid lots of errors, problems,
    cross-browser issues, etc... Here, language is a deprecated attribute.
    type has superseded language and is both backward and forward compatible. So

    <script type="text/javascript" src="pops.js"></script>
    [color=blue]
    >
    > It works in current IE's on multiple platforms and in Apple's Safari.
    > Any ideas about how I might work it for NS?
    >
    > Thanks,
    >
    > Mark
    >
    > // <pops.js>
    >
    > var DEBUGGING=false ;
    > var myTarget=null;
    >
    > function popUp(argURL, argOBJ, argH, argW) {
    > /* Useage example from caller.html:
    > <FORM name="stockForm ">[/color]

    The form element requires an action attribute.
    [color=blue]
    > <INPUT name="txtA" type="text" id="txtA" value="" size="10" />[/color]

    I do not recommend giving the same name attribute value and same id
    attribute value to elements. Giving the same name and id attribute do
    not contribute to code readability, ease of debugging, reviewing by
    others, use of debugger softwares.
    [color=blue]
    > <INPUT name="btnA" type="button" id="btnA"
    > onClick="popUp( 'callee.html', this)" value="." /><BR />
    > </FORM>[/color]

    If this is an xhtml file, then you need to lowercase your element's tags.
    [color=blue]
    > */
    > try {
    > // default to 300x300, otherwise use options offered
    > argH=(!argH || argH==0) ? 300 : argH;
    > argW=(!argW || argW==0) ? 300 : argW;
    > // establish error message in case something goes wrong
    > var Err = new Error();[/color]

    I wonder anyway why you do not just use the javascript console and
    Venkman javascript debugger here.
    The error object is generated in the catch block as an argument; so no
    need to create an Error() object.

    [color=blue]
    > Err.message="mc s.js popUp(" + argURL + ", " + argOBJ.name + ", " +
    > argH + ", " + argW + ") error:\n\nmyTar get not established or window
    > not opened";
    > // set aside the name of the object which will be receiving the
    > value chosen in the popUp window
    > // presumes usage from naming as used above txtA and btnA
    > myTarget=argOBJ .form.name+'.'+ 'txt'+argOBJ.na me.substr(3,
    > argOBJ.name.len gth-3);
    > if (DEBUGGING) alert('myTarget ='+myTarget);
    > // open the popUp
    > listWin=window. open(argURL, 'list', 'height='+argH+ ',
    > width='+argW+', left =100, top=100, location=no, menubar=no,
    > resizable=yes, scrollbars=yes, status=no, toolbar=no');[/color]

    Avoid blank space in the 3rd parameter (arguments string list).
    "windowFeat ures is an optional string containing a comma-separated list
    of options for the new window (do not include any spaces in this list)."


    You can trim and compact all this by remembering that as soon as you
    mention 1 argument in the 3rd parameter, then all other windowFeatures
    are turned off.
    "if you do supply the windowFeatures parameter, then the titlebar and
    hotkeys are still yes by default, but the other features which have a
    yes/no choice are no by default."

    This is also the case for MSIE.
    So:

    listWin=window. open(argURL, 'list', 'height='+argH+ ',
    width='+argW+', left=100,top=10 0,resizable=yes ,scrollbars=yes ');

    will work in NS 6.2+.



    [color=blue]
    > // complain if it didn't work
    > if (myTarget==null || !listWin) throw(Err);
    > }
    > catch (Err)
    > { alert(Err.messa ge); }
    > }
    >
    > function popDown(argVAL) {
    > /* Useage example from callee.html:
    > <A href="#" onClick="popDow n('AMZN')">AMZN </A>
    > */
    > try {
    > // establish error message in case something goes wrong
    > var Err = new Error();
    > Err.message="mc s.js popDown("+argVA L+") error:\n\nmyTar get not set";[/color]

    The error object should not be processed in the try block but rather
    created and processed in the catch block.
    Error handling in JavaScript 1.5:

    [color=blue]
    > var evalMe="opener. "+opener.myTarg et+".value="+"' "+argVAL+"' ";[/color]

    Around here, your code gets complicated. It would be a lot more easier
    to figure out with an url (online html file)... That's always better.
    [color=blue]
    > if (DEBUGGING) alert('evalMe=' +evalMe);
    > eval(evalMe);[/color]

    Avoid eval calls everywhere in all your script functions. There is now a
    solid consensus among regulars of this newsgroup that eval() calls are
    always inferior to more specific methods or attributes.
    [color=blue]
    > // if myTarget != val then complain
    > if (eval("opener." +opener.myTarge t+".value!="+"' "+argVAL+"' "))
    > throw(Err);
    > else window.close();
    > }
    > catch (Err)
    > { alert(Err.messa ge); }
    > }
    >
    > // </pops.js>[/color]

    DU
    --
    Javascript and Browser bugs:

    - Resources, help and tips for Netscape 7.x users and Composer
    - Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x


    Comment

    • Mark Stafford

      #3
      Re: Netscape DOM issue?

      > opener is a window object reference. formName is a form name attribute.[color=blue]
      > You need the document node in between. So:
      >
      > opener.document .formName should reference appropriately the form.[/color]

      That did the trick. Thank you for that and the additional pointers.

      Comment

      Working...