View Full Version : Javascript and XHTML Strict: Need to get JS version
RetroGamer1991
03-01-2006, 12:10 AM
With XHTML strict you can not use the language tag along with the version, but I need to make my code work with different versions of Javascript
Is there some kind of code that gives the version of JavaScript a person's browser has? :confused:
_Aerospace_Eng_
03-01-2006, 01:22 AM
There is no need to specificy the version or language just use
<script type="text/javascript">
//Your script
</script>
All modern browsers support most javascript. Surely if you script needs a language then its quite old. Post the script you are talking about.
RetroGamer1991
03-01-2006, 01:53 AM
I know that part, but there are different versions of javascript, somethings work in one version and and not in an older version of Javascript
Take the "switch" statement, only JS1.2 ore newer supports that. There are several other javascript codes I am working on and they may not work on some older versions of JS, but since I'm using XHTML strict I'm not sure how to find out what version of JS their browser supports :confused:
_Aerospace_Eng_
03-01-2006, 02:03 AM
What browsers are you trying to support? Just check to see if the browser supports a certain method rather than trying to detect the JS version it uses. Again no need to specify the language. If the browsers understands the script it will run it.
RetroGamer1991
03-01-2006, 11:01 AM
Firefox/Mozilla, IE >=4, Safari, Opera
I'm not sure how to test for different browsers, I think IE might be simple to find out how but not sure about Firefox/Mozilla
Jon Hanlon
03-01-2006, 07:28 PM
For IE you can use ScriptEngineMajorVersion() and ScriptEngineMinorVersion().
This table show you which versions of IE support what:
http://msdn.microsoft.com/library/en-us/jscript7/html/jsoriversioninformation.asp?frame=true
Firefox and Mozilla are so new that they'll pretty much support everything.
The trouble is, it's no good just detecting the browser script version as unknown contructs will still cause errors.
if (anEarlyBrowser) {
weekend = (today == "Sat" || today == "Sun")
} else {
switch (today) {
case "Sat":
case "Sun": weekend = true;
break;
default: weekend = false;
}
}
Now in this (silly) example, the early Browser will still parse the script after the "else" (just not execute it). It will spot the "switch" statement which it won't understand, so it will raise an error.
By the way, the version attribute of the script element is an old dinosaur that's been around since Netscape 4. Netscape wrongly anticipated the next standard, so Javascript 1.2 behaves differently to other versions. (Particularly in arrays, dates and strictly equals.) IE6 now seems to ignore the version attribute, so too Firefox 1.5
https://bugzilla.mozilla.org/show_bug.cgi?id=255895
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.