Netscape DOM issue?

M

Mark Stafford

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.formName has no properties"

The following JS is its own file included in caller.html and
callee.html with this syntax <SCRIPT language="JavaScript"
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="mcs.js popUp(" + argURL + ", " + argOBJ.name + ", " +
argH + ", " + argW + ") error:\n\nmyTarget 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.name.substr(3,
argOBJ.name.length-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.message); }
}

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

// </pops.js>
 
D

DU

Mark said:
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.formName has no properties"

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.
The following JS is its own file included in caller.html and
callee.html with this syntax <SCRIPT language="JavaScript"
src="pops.js"></SCRIPT>

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

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

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

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.
<INPUT name="btnA" type="button" id="btnA"
onClick="popUp('callee.html', this)" value="." /><BR />
</FORM>

If this is an xhtml file, then you need to lowercase your element's tags.
*/
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();

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.

Err.message="mcs.js popUp(" + argURL + ", " + argOBJ.name + ", " +
argH + ", " + argW + ") error:\n\nmyTarget 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.name.substr(3,
argOBJ.name.length-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');

Avoid blank space in the 3rd parameter (arguments string list).
"windowFeatures is an optional string containing a comma-separated list
of options for the new window (do not include any spaces in this list)."
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/window.html#1202731

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."
http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/window.html#1202731
This is also the case for MSIE.
So:

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

will work in NS 6.2+.



// complain if it didn't work
if (myTarget==null || !listWin) throw(Err);
}
catch (Err)
{ alert(Err.message); }
}

function popDown(argVAL) {
/* Useage example from callee.html:
<A href="#" onClick="popDown('AMZN')">AMZN</A>
*/
try {
// establish error message in case something goes wrong
var Err = new Error();
Err.message="mcs.js popDown("+argVAL+") error:\n\nmyTarget not set";

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:
http://webbuilder.netscape.com/webbuilding/0-7701-8-5461505-1.html
var evalMe="opener."+opener.myTarget+".value="+"'"+argVAL+"'";

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.
if (DEBUGGING) alert('evalMe='+evalMe);
eval(evalMe);

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.
// if myTarget != val then complain
if (eval("opener."+opener.myTarget+".value!="+"'"+argVAL+"'"))
throw(Err);
else window.close();
}
catch (Err)
{ alert(Err.message); }
}

// </pops.js>

DU
--
Javascript and Browser bugs:
http://www10.brinkster.com/doctorunclear/
- Resources, help and tips for Netscape 7.x users and Composer
- Interactive demos on Popup windows, music (audio/midi) in Netscape 7.x
http://www10.brinkster.com/doctorunclear/Netscape7/Netscape7Section.html
 
M

Mark Stafford

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.

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

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,774
Messages
2,569,596
Members
45,142
Latest member
arinsharma
Top