Javascript 1.3

  • Thread starter Christopher Benson-Manica
  • Start date
C

Christopher Benson-Manica

Can anyone tell me which browsers implement Javascript 1.3?
Specifically, which browsers will handle the identity operator (===)
correctly? I ask because jslint suggests using it, but I don't want
to get too cutting edge.
 
M

Martin Honnen

Christopher said:
Can anyone tell me which browsers implement Javascript 1.3?
Specifically, which browsers will handle the identity operator (===)
correctly? I ask because jslint suggests using it, but I don't want
to get too cutting edge.

Netscape browsers support Javascript 1.3 and === since 4.06 and later
version, IE (at least on Windows) should have support for === since IE4
but that is only from my recollection, the JScript docs don't tell that
in detail.
 
C

Christopher Benson-Manica

Martin Honnen said:
Netscape browsers support Javascript 1.3 and === since 4.06 and later
version, IE (at least on Windows) should have support for === since IE4
but that is only from my recollection, the JScript docs don't tell that
in detail.

I see. Another question: If I explicitly specify JS1.3 like so:

<script type=\"text/javascript1.3\">

(well, I suppose that's how it's done...), and the browser does not
implement 1.3, what will the browser do?
 
M

Martin Honnen

Christopher Benson-Manica wrote:

Another question: If I explicitly specify JS1.3 like so:

<script type=\"text/javascript1.3\">

(well, I suppose that's how it's done...), and the browser does not
implement 1.3, what will the browser do?

If you want to use a version then you would need the language attribute e.g.
<script language="JavaScript1.3">
older browsers like Netscape 4.00-4.05 or Netscape 3 then ignore the
script element's content.

But nowadays you shouldn't need to use <script language>, simply use
<script type="text/javascript">
the need for versioning your script elements is gone, if someone is
still around with Netscape 4 then hardly with 4.00-4.05 and with IE5 and
later there shouldn't be any problems either
 
R

Richard Cornford

Martin Honnen wrote:
... , IE (at least on Windows) should have support for === since
IE4 but that is only from my recollection, the JScript docs don't
tell that in detail.

I believe that it was IE 5.0 that was the first IE browser to be
released with a JScript version that supported - === -, but JScript on
windows is independent of the browsers so even an IE 4 user may have a
later JScript version installed (if they have updated WSH, for example)
and IE 4 would use that version to execute scripts.

Richard.
 
M

Matt Kruse

Martin Honnen said:
If you want to use a version then you would need the language attribute e.g.
<script language="JavaScript1.3">
older browsers like Netscape 4.00-4.05 or Netscape 3 then ignore the
script element's content.
But nowadays you shouldn't need to use <script language>, simply use
<script type="text/javascript">

This is often said, but this is a good example - if a person wants to use
===, and doesn't specify the language="Javasscript1.2" then how can they
make sure older browsers don't execute the code block?

The typical answer is "test for features" but you can't test for new
operators like you can for properties of objects. If you use try/catch, then
that breaks in older browsers.

How can a developer use === and not break older browsers?
 
M

Martin Honnen

Matt said:
This is often said, but this is a good example - if a person wants to use
===, and doesn't specify the language="Javasscript1.2" then how can they
make sure older browsers don't execute the code block?

1.2 doesn't help as === is 1.3 but maybe that is a typo.

The typical answer is "test for features" but you can't test for new
operators like you can for properties of objects. If you use try/catch, then
that breaks in older browsers.

How can a developer use === and not break older browsers?

One way I see is using several script blocks and probably external
script files with different versions (e.g. one using === and one using
==) in the following way:

<script type="text/javascript">
var idTest = false;
</script>
<script type="text/javascript">
idTest = 1 === 1;
</script>
<script type="text/javascript">
if (idTest) {
var src = 'fileId.js';
}
else {
var src = 'file.js';
}
document.write('<script type="text/javascript" src="' + src +
'"><\/script>');
</script>

With older browsers the second script block should yield a syntax error
and therefore in the third script block the variable idTest is false so
you can write out a reference to a file.

A similar scheme should work for try/catch e.g.

<html>
<head>
<title>Checking for try/catch</title>
<script type="text/javascript">
var tcTest = false;
</script>
<script type="text/javascript">
try {
tcTest = true;
}
catch (e) {

}
</script>
<script type="text/javascript">
if (tcTest) {
var src = 'test20040416tc.js';
}
else {
var src = 'test20040416.js';
}
document.write('<script type="text/javascript" src="' + src +
'"><\/script>');
</script>
</head>
<body>
</body>
</html>

with test20040416tc.js being for test cases just

alert('Could use try/catch here.');

and the other file then

alert('Can\'t use try/catch here.');



That way if you try the test case with Netscape 4 which doesn't support
try/catch no error is generated and you can load a script file which
doesn't use try/catch.


But as said I think you can safely ignore browsers not supporting ===,
you can't forever try to make sure your script doesn't break with
antiquated browsers.
As for try/catch if you still think you have to deal with Netscape 4
users then you have the choice to avoid try/catch totally or use an
approach as outlined above. There are also other ways to use try/catch
in certain browsers safely (e.g. IE with conditional comments, Netscape
6/7 respectively Mozilla with <script type="text/javascript;
version=1.5">) if you are only scripting features for those browser like
XMLHttpRequest.
 
M

Michael Winter

[snip]
How can a developer use === and not break older browsers?

You probably can't, but you can avoid it altogether.

function isExact( a, b ) {
return(( typeof a == typeof b ) && ( a == b ));
}

This is results in exactly the same algorithm, just less efficient (the
typeof comparison is a string comparison, rather than a direct type check).

Mike
 
M

Matt Kruse

Michael Winter said:
You probably can't, but you can avoid it altogether.

Which is why I think it's ridiculous that type="text/javascript" is supposed
to replace language="Javascript".

Same think with try/catch, or any other keyword additions and language
changes in different versions.
If you're developing for an internet audience, you can't use any of these
new features, because there is no way (that I've found) to degrade nicely,
without relying on language="Javascript1.3", etc.

Causing a syntax error while determining whether or not an operator is
supported (as another poster suggested) isn't really a good solution, IMO.
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen in
Richard Cornford
Martin Honnen wrote:


I believe that it was IE 5.0 that was the first IE browser to be
released with a JScript version that supported - === -, but JScript on
windows is independent of the browsers so even an IE 4 user may have a
later JScript version installed (if they have updated WSH, for example)
and IE 4 would use that version to execute scripts.

The initial UK release of Win98 came with an MSIE4 that accepts all but
the now commented-out line of
var A, B
A=B
A==B
A===B
// A====B
 
L

Lasse Reichstein Nielsen

Matt Kruse said:
Same think with try/catch, or any other keyword additions and language
changes in different versions.
If you're developing for an internet audience, you can't use any of these
new features, because there is no way (that I've found) to degrade nicely,
without relying on language="Javascript1.3", etc.

The problem with the language attribute is that not all browser honor it,
and that later versions are not necessarily compatible with earlier code.
Example of the latter:
<script language="Javascript1.2">
var a=1,b=2;
if (a=b) {alert("Foo!");}
</script>

This should not alert "Foo!", but in browsers that support Javascript
1.3 and *not* 1.2, it will (one example is IE 6).
That is, supporting Javascript1.3 does not mean that one supports 1.2!

/L
 
M

Matt Kruse

Lasse Reichstein Nielsen said:
<script language="Javascript1.2">
var a=1,b=2;
if (a=b) {alert("Foo!");}
</script>
This should not alert "Foo!", but in browsers that support Javascript
1.3 and *not* 1.2, it will (one example is IE 6).

I'm not sure what you mean, here. It _should_ alert Foo, from what I
understand. a=b evaluates to 2 as an expression, which is true, which makes
the alert fire. If b is 0, then it does not fire. The exception is in
Netscape browsers, which treated this situation differently when explicitly
specifying "Javascript1.2" as the language.
That is, supporting Javascript1.3 does not mean that one supports 1.2!

It certainly should. I think the example you're pointing out is an exception
in Netscape browsers.
Someone feel free to correct me :)
 
L

Lasse Reichstein Nielsen

Matt Kruse said:
I'm not sure what you mean, here. It _should_ alert Foo, from what I
understand. a=b evaluates to 2 as an expression, which is true, which makes
the alert fire. If b is 0, then it does not fire. The exception is in
Netscape browsers, which treated this situation differently when explicitly
specifying "Javascript1.2" as the language.

Yes, because they actually implement Javascript1.2. In JS1.2, "=" in
if-statments was treated as a comparison. In JS1.3 (and 1.1) it wasn't.

If you request JS1.3, you don't want browsers that doesn't support it
(but only, e.g., 1.2) to run the script. Running an 1.3 script with
an 1.2 interpreter will give wrong results.

My point is that running an 1.2 script with an 1.3 interpreter will
*also* give the wrong result. However, no browser supporting only 1.3
scripts will skip script with language="Javascript1.2".
It certainly should.

Only if 1.3 is a pure extension of 1.2. It isn't.
I think the example you're pointing out is an exception
in Netscape browsers.

That exception would be recognizing and respecting the language
attribute.

/L
 
R

Richard Cornford

Dr John Stockton wrote:
The initial UK release of Win98 came with an MSIE4 that accepts all
but the now commented-out line of
var A, B
A=B
A==B
A===B
// A====B

Out of curiosity, what sort of output do you get from the following:-

var out = 'No ScriptEngine Funciton';
if(window.ScriptEngine){
out = ScriptEngine();
if(window.ScriptEngineMajorVersion){
out += ' '+ScriptEngineMajorVersion();
}
if(window.ScriptEngineMinorVersion){
out += '.'+ScriptEngineMinorVersion();
}
if(window.ScriptEngineBuildVersion){
out += '.'+ScriptEngineBuildVersion();
}
}
alert(out);

Richard.
 
L

Lasse Reichstein Nielsen

Out of curiosity, what sort of output do you get from the following:-

I just tested a stand-alone version of IE 4 that accepts ===, and it
reports: JScript 3.1.3510

/L
 
J

Jim Ley

Same think with try/catch, or any other keyword additions and language
changes in different versions.
If you're developing for an internet audience, you can't use any of these
new features, because there is no way (that I've found) to degrade nicely,
without relying on language="Javascript1.3", etc.

but that's never been a reliable solution anyway, it was ignored by
too many of the old browsers - the ones we need to protect.
Causing a syntax error while determining whether or not an operator is
supported (as another poster suggested) isn't really a good solution, IMO.

Absolutely, that's definately unacceptable, I wouldn't use ===, it's
one of things I disagree with jslint on.

Jim.
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen in
Richard Cornford
Out of curiosity, what sort of output do you get from the following:-

var out = 'No ScriptEngine Funciton';
if(window.ScriptEngine){
out = ScriptEngine();
if(window.ScriptEngineMajorVersion){
out += ' '+ScriptEngineMajorVersion();
}
if(window.ScriptEngineMinorVersion){
out += '.'+ScriptEngineMinorVersion();
}
if(window.ScriptEngineBuildVersion){
out += '.'+ScriptEngineBuildVersion();
}
}
alert(out);

It's easier for me without the alert - that is equivalent to

out = "JScript 3.1.2124"

on my system.
 

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
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top