Monday, March 9, 2009

How To Turn on JavaScript


Internet Explorer for Windows
Find the "Internet Options" option in the menubar of your browser (it's probably located in the Tools menu). Click on the "Security" tab. Make sure the "Internet" globe icon is highlighted. Click on the "Custom Level..." button to bring up the security options for your browser. Search through the menu for the "Active scripting" option. Make sure "Enable" is selected. Click the "OK" button. Close this window and click the "Refresh" button of the page requiring Javascript.

Netscape for Windows
Find the "Preferences" option in the menubar of your browser (it's probably located in the Edit menu). Select the "Advanced" arrow in the list on the left side of the window. Make sure that the checkbox next to "Enable JavaScript" is checked. Click the "OK" button. Close this window and click the "Reload" button of the page requiring Javascript.

Safari for Macintosh
Go to and select the "Preferences..." option in the "Safari" menu. Click on the "Security" icon in the top row of preference options. Under the "Web Content:" category, make sure the "Enable JavaScript" box is checked. Close this window and click the "Reload" button of the page requiring Javascript.
Internet Explorer for Macintosh
Find the "Preferences" option in the menubar of your browser (it's probably located in the Edit menu). Select the "Web Content" bullet in the list on the left side of the window. Find the "Active Content" section. Make sure that the checkbox next to "Enable scripting" is checked. Click the "OK" button. Close this window and click the "Refresh" button of the page requiring Javascript.

Netscape for Macintosh
Find the "Preferences" option in the menubar of your browser (it's probably located in the Edit menu). Select the "Advanced" arrow in the list on the left side of the window. Make sure that the checkbox next to "Enable JavaScript" is checked. Click the "OK" button. Close this window and click the "Reload" button of the page requiring Javascript.

Java Script

Security

JavaScript and the DOM provide the potential for malicious authors to deliver scripts to run on a client computer via the web. Browser authors contain this risk using two restrictions. First, scripts run in a sandbox in which they can only perform web-related actions, not general-purpose programming tasks like creating files. Second, scripts are constrained by the same origin policy: scripts from one web site do not have access to information such as usernames, passwords, or cookies sent to another site. Most JavaScript-related security bugs are breaches of either the same origin policy or the sandbox.

Cross-site vulnerabilities
Main articles: Cross-site scripting and Cross-site request forgery

A common JavaScript-related security problem is cross-site scripting, or XSS, a violation of the same-origin policy. XSS vulnerabilities occur when an attacker is able to cause a target web site, such as an online banking website, to include a malicious script in the webpage presented to a victim. The script in this example can then access the banking application with the privileges of the victim, potentially disclosing secret information or transferring money without the victim's authorization. A solution to XSS vulnerabilities is to use HTML escaping whenever displaying untrusted data.

XSS vulnerabilities can also occur because of implementation mistakes by browser authors.

Another cross-site vulnerability is cross-site request forgery or CSRF. In CSRF, code on an attacker's site tricks the victim's browser into taking actions the user didn't intend at a target site (like transferring money at a bank). It works because, if the target site relies only on cookies to authenticate requests, then requests initiated by code on the attacker's site will carry the same legitimate login credentials as requests initiated by the user. In general, the solution to CSRF is to require an authentication value in a hidden form field, and not only in the cookies, to authenticate any request that might have lasting effects. Checking the HTTP Referrer header can also help.

What is JavaScript?


What is JavaScript?

JavaScript is the Netscape-developed object scripting language used in millions of web pages and server applications worldwide. Netscape's JavaScript is a superset of the ECMA-262 Edition 3 (ECMAScript) standard scripting language, with only mild differences from the published standard.

Contrary to popular misconception, JavaScript is not "Interpretive Java". In a nutshell, JavaScript is a dynamic scripting language supporting prototype based object construction. The basic syntax is intentionally similar to both Java and C++ to reduce the number of new concepts required to learn the language. Language constructs, such as if statements, for and while loops, and switch and try ... catch blocks function the same as in these languages (or nearly so.)

JavaScript can function as both a procedural and an object oriented language. Objects are created programmatically in JavaScript, by attaching methods and properties to otherwise empty objects at run time, as opposed to the syntactic class definitions common in compiled languages like C++ and Java. Once an object has been constructed it can be used as a blueprint (or prototype) for creating similar objects.

JavaScript's dynamic capabilities include runtime object construction, variable parameter lists, function variables, dynamic script creation (via eval), object introspection (via for ... in), and source code recovery (JavaScript programs can decompile function bodies back into their source text)

Intrinsic objects are Number, String, Boolean, Date, RegExp, and Math.

For a more in depth discussion of JavaScript programming follow the JavaScript resources links below.


What JavaScript implementations are available?

mozilla.org hosts two JavaScript implementations. The first ever JavaScript was created by Brendan Eich at Netscape, and has since been updated (in JavaScript 1.5) to conform to ECMA-262 Edition 3. This engine, code named SpiderMonkey, is implemented in C. The Rhino engine, created primarily by Norris Boyd (also at Netscape) is a JavaScript implementation in Java. Like SpiderMonkey, Rhino is ECMA-262 Edition 3 compliant.

Each mozilla.org JavaScript engine exposes a public API applications can call on for JavaScript support. By far, the most common host environment for JavaScript is web browsers. Web browsers typically use the public API to create 'host objects' responsible for reflecting the DOM into JavaScript.

Another common application for JavaScript is as a (web) server side scripting language. A JavaScript web server would expose host objects representing a HTTP request and response objects, which could then be manipulated by a JavaScript program to dynamically generate web pages.

For more information on embedding JavaScript in your own applications, follow either the SpiderMonkey or Rhino links below, or visit us on the netscape.public.mozilla.jseng newsgroup.

Imperative and structured

JavaScript supports all the structured programming syntax in C (e.g., if statements, while loops, switch statements, etc.). One partial exception is scoping: C-style block-level scoping is not supported. JavaScript 1.7, however, supports block-level scoping with the let keyword. Like C, JavaScript makes a distinction between expressions and statements.

Dynamic

dynamic typing
As in most scripting languages, types are associated with values, not variables. For example, a variable x could be bound to a number, then later rebound to a string. JavaScript supports various ways to test the type of an object, including duck typing.

objects as associative arrays
JavaScript is almost entirely object-based. Objects are associative arrays, augmented with prototypes (see below). Object property names are associative array keys: obj.x = 10 and obj["x"] = 10 are equivalent, the dot notation being merely syntactic sugar. Properties and their values can be added, changed, or deleted at run-time. The properties of an object can also be enumerated via a for...in loop.

run-time evaluation
JavaScript includes an eval function that can execute statements provided as strings at run-time.

Functional

Functional

first-class functions
Functions are first-class; they are objects themselves. As such, they have properties and can be passed around and interacted with like any other object.

inner functions and closures
Inner functions (functions defined within other functions) are created each time the outer function is invoked, and variables of the outer functions for that invocation continue to exist as long as the inner functions still exist, even after that invocation is finished (e.g. if the inner function was returned, it still has access to the outer function's variables) — this is the mechanism behind closures within JavaScript.

Prototype-based

prototypes
JavaScript uses prototypes instead of classes for defining object properties, including methods, and inheritance. It is possible to simulate many class-based features with prototypes in JavaScript.

functions as object constructors
Functions double as object constructors along with their typical role. Prefixing a function call with new creates a new object and calls that function with its local this keyword bound to that object for that invocation. The function's prototype property determines the new object's prototype.

functions as methods
Unlike many object-oriented languages, there is no distinction between a function definition and a method definition. Rather, the distinction occurs during function calling; a function can be called as a method. When a function is invoked as a method of an object, the function's local this keyword is bound to that object for that invocation.

Miscellaneous

run-time environment
JavaScript typically relies on a run-time environment (e.g. in a web browser) to provide objects and methods by which scripts can interact with "the outside world". (This is not a language feature per se, but it is common in most JavaScript implementations.)

variadic functions
An indefinite number of parameters can be passed to a function. The function can both access them through formal parameters and the local arguments object.

array and object literals
Like many scripting languages, arrays and objects (associative arrays in other languages) can each be created with a succinct shortcut syntax. In fact, these literals form the basis of the JSON data format.

regular expressions
JavaScript also supports regular expressions in a manner similar to Perl, which provide a concise and powerful syntax for text manipulation that is more sophisticated than the built-in string functions.