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.su bstr(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="+"'"+arg VAL+"'";
if (DEBUGGING) alert('evalMe='+evalMe);
eval(evalMe);
// if myTarget != val then complain
if (eval("opener."+opener.myTarget+".value!="+"'"+arg VAL+"'"))
throw(Err);
else window.close();
}
catch (Err)
{ alert(Err.message); }
}
// </pops.js> 2 1996
Mark Stafford wrote: 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
<script type="text/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">
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.su bstr(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/...w.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/...w.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,scro llbars=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/webbu...5461505-1.html
var evalMe="opener."+opener.myTarget+".value="+"'"+arg VAL+"'";
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!="+"'"+arg VAL+"'")) 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/doctorunc...e7Section.html
> 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. This discussion thread is closed Replies have been disabled for this discussion. Similar topics
4 posts
views
Thread by Yvan J. Gagnon |
last post: by
|
9 posts
views
Thread by rez |
last post: by
|
13 posts
views
Thread by Gaurav |
last post: by
|
11 posts
views
Thread by Jonny |
last post: by
|
2 posts
views
Thread by Joy |
last post: by
|
18 posts
views
Thread by Dennis |
last post: by
|
5 posts
views
Thread by zaw |
last post: by
|
6 posts
views
Thread by christian9997 |
last post: by
|
13 posts
views
Thread by M B HONG 20 |
last post: by
|
7 posts
views
Thread by David Laub |
last post: by
| | | | | | | | | | |