Errors in NS 4.7, works in recent browsers, please help

Errors in NS 4.7, works in recent browsers, please help

Post by ASallad » Thu, 08 Jan 2004 11:11:49


ello,

I've scoured my books and the web, but am still daunted, hopefully some of
the users in this newsgroup will have advice for my problem.

I am not an experienced javascript programmer, but have gotten my code to
work well, without errors on IE, Opera and netscapes recent builds. While
testing, I found that it doesnt execute on Netscape 4.7

In the head I have a script that creates a custom object/class for products,
with properties and methods.

The properties and methods are then called later in the body to write out
product information. I generate the script and innitialize objects from a
database which writes the class and creates the objects. I wont touch on the
database here, butit writes out static files, so it's not really an issue.
My code follows...

<HTML>
<HEAD>
<script language="JavaScript">
stID = 7
function Prod(tC, tN, tP, tS, tT) {
this.P=tP;//Price
this.S=tS;//Ship
this.T=tT;//Total
this.N=tN;//Name
this.C=tC;//Code
this.U="https://www.mpllc.net/order.aspx?prod=" + this.C + "&st=" +
stID; //URL
this.WP = WP; // WritePrice
function WP() {
document.write(this.P);
}
this.WN = WN; // WriteName
function WN() {
document.write(this.N);
}
this.WS = WS; // WriteShipping Fee
function WS() {
document.write(this.S);
}
this.WT = WT; // WriteTotal
function WT() {
document.write(this.T);
}
this.Link = Link;//Forward browser to purchase
function Link() {
self.location = this.U;
}
this.LN = LN;//Write Link Tag with Product Name as Link Text
function LN() {
str1 = "<a href='" + this.U + "'>" + this.N + "</a>";
document.write(str1);
}
this.LP = LP;//Write Link Tag with Price as Link Text
function LP() {
str1 = "<a href='" + this.U + "'>" + this.P + "</a>";
document.write(str1);
}
this.LS = LS;//Write Link Tag with Shipping as Link Text
function LS() {
str1 = "<a href='" + this.U + "'>" + this.S + "</a>";
document.write(str1);
}
this.LT = LT;//Write Link Tag with Total as Link Text
function LT() {
str1 = "<a href='" + this.U + "'>" + this.T + "</a>";
document.write(str1);
}
this.LB = LB;//Write Link Tag with Buy as Link Text
function LB() {
str1 = "<a href='" + this.U + "'>Buy</a>";
document.write(str1);
}
this.LNP = LNP;//Write Link Tag with Name and Price as Link Text
function LNP() {
str1 = "<a href='" + this.U + "'>" + this.N + " " + this.P + "</a>";
document.write(str1);
}
this.LNT = LNT;//Write Link Tag with Name and Total as Link Text
function LNT() {
str1 = "<a href='" + this.U + "'>" + this.N + " " + this.T + "</a>";
document.write(str1);
}
}
acip_10_30 = new Prod("acip_10_30", "Aciphex 10mg 30", "$179.00",
"$18.00", "$197.00");

</script>


</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<a href="javascript:acip_10_30.Link();"><script
language="javascript">acip_10_30.WN();</script></a>
<br />
<a href="javascript:acip_10_30.Link();"><script
language="javascript">document.write(acip_10_30.N);</script>
 
 
 

Errors in NS 4.7, works in recent browsers, please help

Post by Thomas 'Po » Fri, 23 Jan 2004 19:35:27

Sallade wrote:


First of all, no version of Netscape 4.7x knows XHTML, so do not
use it if you want to support this UA. And there are other good
reasons for not using XHTML nowadays.[1]

Secondly, there are differences between Netscape 4.7x versions.[2]


There are no classes in JavaScript 1.x and its related languages,
you have created a prototype (object) by a constructor (function).[3]


Note that every method is a property of type "function" (IE shows
"object" [IMHO falsely] as every function is a Function object.)


If you already have a server-side application, use it instead for
the parts that do not work without the server. See below.


For valid (X)HTML, the DOCTYPE and character set declarations are
required.[4]


For valid HTML 4(.01), the "type" attribute is required.[4]
Not that I think NS4 cares much of it, but other UAs will.


You better end all of your statements with a semicolon, do
not rely on auto-completion.


You better allow the properties to have a default value, otherwise
they are assigned "undefined" if an argument is left out:

this.foobar = argument_identifier || default_value;


Are you accessing https: from https:? If yes, you have just
run into the Same Origin Policy[5].

If you are writing URIs dynamically, you should escape "&" with
"&" (one time ;-)), for you will create invalid (X)HTML
otherwise.[4]


If an inner function is a property anyway, you should assign it
directly:

this.foobar =
function foobar()
{
// ...
};

Note that a "function" statement within a statement (incl. assignment)
requires JavaScript >= 1.2, according to the Core JavaScript 1.5
Reference.[6] (The same Reference states that Netscape 4.x supports
JavaScript 1.2, though it is, alas, not reliable; I found out that
Netscape 4.79 supports anonymous functions [i.e. created using the
"function" operator of JavaScript 1.5/ECMAScript 3] although the
Reference states that Netscape 4.7x supports JavaScript 1.3 only.
So you need to test for it.)

And you better give your methods speaking identifiers from which
you can make a good guess what they actually do.

(Note that document.write(...) overwrites a loaded document, so
do not use it after the document has be loaded, i.e. do not call
methods that call it then. You actually do not do so but remember
this if you are tempted to do so later. There are other DOM
methods you can use instead, even in NN4.)


Do not save numeric data as (character) strings. Save it as number
and if a unit (e.g. a currency) is attached to it, save the unit
separately (e.g. through a prototype constructor) or do not save it
at all, depending on your needs.


This is invalid (X)HTML. The (X)HTML "form"
element does not have a "runat" attribute (in
neither DTD).


The javascript: URI scheme is proprietary and used out of
purpose (generating content through Javascript expressions)
here. Use intrinsic event-handler attributes and avoid
"javascript:" if you can, see the FAQ.

Furthermore, including "script" elements in "a" elements
can get you into trouble. You better write the whole
"a" element dynamically, including its content.


I read this as an XHTML "br" element specified through
SHORTTAG syntax,


but the "language" attribute is deprecated in both
HTML 4.01 and XHTML 1.0. There is not one in XHTML
1.1.


So you are generating all of the docum
 
 
 

Errors in NS 4.7, works in recent browsers, please help

Post by Thomas 'Po » Fri, 23 Jan 2004 19:38:09


Err, "https: from http:?", of course.


PointedEars