How to run the JavaScript if above version?

H

howa

E.g. I only want if my browser support JavaScript 1.9


<script type="text/javascript" language="JavaScript1.9">
alert("Hello");
</script>
 
P

Peter Michaux

E.g. I only want if my browser support JavaScript 1.9

<script type="text/javascript" language="JavaScript1.9">
alert("Hello");
</script>

Why do you want to do that?

Peter
 
H

howa

The above is just an example...

For example, if I want to take some advance features of JavaScript
version, I don't want older client to see the syntax error.
 
R

RobG

Please don't top-post or quote signatures. Posting order restored.

The above is just an example...

For example, if I want to take some advance features of JavaScript
version, I don't want older client to see the syntax error.

Use standard feature detection and add the desired functionality to
UAs that lack it:

if (typeof Array.prototype.reduce != 'function') {
// add your own reduce method
}


Set your feature detection for say version 1.5 or maybe 1.3 and you
don't care what ECMAScript implementation is being used.
 
P

Peter Michaux

Please don't top-post or quote signatures. Posting order restored.

I don't know if there is a way to do what you want with some technique
like the "language" attribute for recent versions of JavaScript. I've
never bothered trying.

But my curiosity remains.

First, I thought it was JavaScript 1.8 that just shipped with Firefox
3.

Second, assuming you have a browser with JavaScript 1.9, what are you
doing where you desperately need JavaScript 1.9 in production. If it
is just experimenting then you don't need to detect the language
version. If it really is production, JavaScript 1.9 will not be wide
spread for many years to come so I wouldn't see the point as most
browsers won't have support for it.
Use standard feature detection and add the desired functionality to
UAs that lack it:

if (typeof Array.prototype.reduce != 'function') {
// add your own reduce method
}

Set your feature detection for say version 1.5 or maybe 1.3 and you
don't care what ECMAScript implementation is being used.

I'm not quite sure how that avoids syntax errors. You could test for
features of the language that are in JavaScript 1.9. If those features
are present then only load script files that would other syntax error
in browsers missing JavaScript 1.9 support. Seems like an indirect
test for syntax. It might be more direct to use a try-catch block with
an eval inside where the evaluated code includes the desired syntax.
Then load the script files with JavaScript 1.9 syntax.


Peter
 
T

Thomas 'PointedEars' Lahn

howa said:
E.g. I only want if my browser support JavaScript 1.9

<script type="text/javascript" language="JavaScript1.9">
alert("Hello");
</script>

JavaScript 1.9 -- that would be Firefox 4, would it not?

Anyhow, MDC explains how to do it for JavaScript 1.8 as
supported in Firefox 3:

<script type="application/javascript;version=1.8">
... your code ...
</script>

<http://developer.mozilla.org/en/docs/New_in_JavaScript_1.8>

And now your transfer effort, please.


PointedEars
 
R

RobG

I'm not quite sure how that avoids syntax errors.

I think you misunderstood my point, which probably means it was poorly
stated. I meant do feature detection for features introduced after
1.5 or 1.3 as appropriate.
You could test for
features of the language that are in JavaScript 1.9. If those features
are present then only load script files that would other syntax error
in browsers missing JavaScript 1.9 support.

That might be called "language version inference". :)
 
B

Bart Van der Donck

I don't know if there is a way to do what you want with some technique
like the "language" attribute for recent versions of JavaScript. I've
never bothered trying.
But my curiosity remains.

Maybe worth a glance:
http://bclary.com/2004/08/27/javascript-version-incompatibilities

The OP's idea should work in theory; but I think it's a bit reckless
to fully lean on the version as specified in the language-attribute.
For example, how would this relate to Microsoft's JScript (eg. my
MSIE7 only claims to support javascript up to 1.3.).

I would prefer the usual object detection as well.
 

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

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top