Re: How to run the JavaScript if above version?
- From: Peter Michaux <petermichaux@xxxxxxxxx>
- Date: Wed, 2 Jul 2008 22:50:21 -0700 (PDT)
On Jul 2, 9:40 pm, RobG <rg...@xxxxxxxxxxxx> wrote:
On Jul 3, 2:08 pm, howa <howac...@xxxxxxxxx> wrote:
Please don't top-post or quote signatures. Posting order restored.
On 7月3日, 上午11時18分, Peter Michaux <petermich...@xxxxxxxxx> wrote:
On Jul 2, 7:47 pm, howa <howac...@xxxxxxxxx> wrote:
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?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.
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
.
- Follow-Ups:
- Re: How to run the JavaScript if above version?
- From: Bart Van der Donck
- Re: How to run the JavaScript if above version?
- From: RobG
- Re: How to run the JavaScript if above version?
- References:
- How to run the JavaScript if above version?
- From: howa
- Re: How to run the JavaScript if above version?
- From: Peter Michaux
- Re: How to run the JavaScript if above version?
- From: howa
- Re: How to run the JavaScript if above version?
- From: RobG
- How to run the JavaScript if above version?
- Prev by Date: Re: How to run the JavaScript if above version?
- Next by Date: Re: How to get uclibc style timezone string (e.g GMT+0IST-1,M3.5.0/01:00:00,M10.5.0/02:00:00) from javascript
- Previous by thread: Re: How to run the JavaScript if above version?
- Next by thread: Re: How to run the JavaScript if above version?
- Index(es):
Relevant Pages
|