JScript
Join the Discussion
Javascript and JScript are two similar but not identical programming languages. Depending on which browser the person who is visiting your page is using the code between your script tags that you have defined as Javascript will be processed as either Javascript or as JScript depending on which of the two languages that the browser supports. Internet Explorer supports JScript and not Javascript while other browsers support Javascript but not JScript.
The best way to handle the differences between Javascript and JScript is to use feature sensing. If you first test whether the Javascript way of doing something is supported then you can have your code process that way when it is supported. If t isn't you then test if the JScript way is supported and if it is you do it that way instead. For example Javascript uses addEventListener() to add event listeners to a web page while JScript uses attachEvent() to do the same thing so you test for which of them is supported before using it.
JScript supports a lot of functionality that Javascript does not. Most of this additional functionality is intended for use on Intranets where the configuration of all of the computers accessing the page is known and there is no security risk. Javascript does not provide equivalent functionality because most of that additional functionality presents a major security risk if used on the internet. You should avoid using the additional functionality that JScript provides when coding for the internet both because only some of your visitors will be using browsers that understand it and also because many of your visitors will have disabled that JScript functionality in their browser because of the security risk that is associated with allowing it so that it may not run even on browsers that do understand it.
Internet Explorer lacks support for a lot of the standard CSS functionality supported by other browsers and you can often use JScript to add that missing functionality into IE without providing the equivalent Javascript functionality (since it isn't needed as the browsers that support Javascript also support the standard stylesheet commands). Internet Explorer also allows you to embed JScript into CSS using the non-standard expressioncommand to set the value of an attribute. For example you can use JScript to provide an equivalent to max-width and min-width by setting setting the width attribute based on the space available within the browser like this:
* html #content{width: expression(document.body.clientWidth > 850 ? "850px" : (document.body.clientWidth < 571 ? "570px" : "94%"));}
Most of the differences between JScript and Javascript can be handled by using feature sensing but there may be rare occasions where you need to positively identify which of these two languages that the browser supports. The simplest way to tell this is to use conditional comments which JScript supports but which Javascript does not. The following example demonstrates using conditional comments in JScript to explisitly test if the browser supports JScript:
@if (@_jscript)
alert('This browser is running JScript');
@end
@*/
As far as Javascript is concerned this is just one big comment but JScript recognises the /*@cc_on @*/ as code that contains special conditional statements. These Statements start with @if followed by the special condition identifier to test for (@_jscript is the identifier to test for JScript support), and optional @else and are ended by @end. You can even use a conditional comment like this to selectively skip over Javascript code when JScript is running, for example:
@if (@_jscript)
alert('This browser is running JScript');
@else */
alert('This browser is NOT running JScript'); /*
@end
@*/
In this instance because JScript understands the conditional code it processes the conditional if statement appropriately. Browsers that run Javascript instead of JScript just see the two comments and simply run the code in between them (which just happens to be within the else part of the conditional statement.
Javascript and JScript are two similar but not identical programming languages. With careful use of feature sensing, coding of JScript in CSS and the use of JScript conditional code we can write code that will produce the same results (or at least very similar results) regardless of ehich of the two languages that our visitor's browser supports.

