Navigation path

JavaScript

Mandatory requirementUse of JavaScript (JS) is permitted but not encouraged. Read more about its use.

 

View all IPG Rules

JavaScript is a programming language used to write scripts to add certain features to websites - pull-down menus, animated buttons, pop-up windows etc.

 

Description

While other languages also exist, JavaScript is the most compatible with standard ECMAScript and is supported by most browsers.

JavaScript is easy to learn. Scripts are mostly interpreted through the client's browser, with no need for server-side operations.

JavaScript code can be  called up via a link to an external file with the extension .js  or included in the HTML page. 

JavaScript tags:
Beginning of script : <script type="text/javascript">
End of script : </script>.

JavaScript can also be used on servers.

Limitations of JavaScript:

  • interpretation depends on browser type and version
  • the source code is visible, so there is zero confidentiality
  • the language is simple and so are its applications

Examples where JavaScript adds real value:

  • improving navigation options
  • validating forms
  • monitoring and routing according to the user's configuration

  

 
 

Use on EUROPA websites

Use of JavaScript (JS) is permitted but not encouraged. Current version 5+ browsers can read JS but it can be interpreted differently depending on the browser. Most browsers offer the option of switching off JS, so if you use it without offering alternatives, some users will be unable to use some features on your site. This is particularly important for navigation functions.

  • Use JS only if it adds real value to your site, not just for eye-catching effects.
  • The standard template uses files containing JavaScript. The language selection tool is available in both JavaScript and non-JavaScript. If you use JavaScript, please use the templates containing the presentation codes for all the official languages. The templates must be adapted according to the languages available for the page concerned.
  • The content and main functionality of a website must not depend on scripting. If any functionality is implemented using script, provide an alternative.
  • Always check that JavaScripts are device independent and compatible with assistive technology.
  • Put scripts code in a separate file and reference it from the <head> section of each page.
  • Avoid interfering with normal browser behaviour. Scripting should not be used to mimic browser behaviour or to or override normal browser functionality (like "Back").
  • When using event handlers, use only those that are device independent (e.g., do not require the use of the mouse only).
  • Web pages that utilize scripting must be fully navigable using a keyboard.
  • Do not generate content on the fly. Normally, it is not detected by screen readers and other assistive technology, and can confuse users by interrupting linear navigation.
  • Do not open new windows or jump to a new page without warning the user first.
  • Use always unobtrusive scripting: Markup should be completely free of any script code. Avoid including script in <script> sections within the document.
  • Code always using the DOM (Document Object Model). The DOM is a way of representing structured documents (HTML or XML, for example) independently of any programming language, avoiding browser compatibility problems. Some of the advantages of scripting the DOM are:
    • Separation: functionality added in script is separate from the structure/content layer and the presentation layer.
    • Compatibility: using the DOM easily avoids incompatibility problems.
    • Accessibility: if scripting is turned off, the scripted functionality does not work, but the user can still access the underlying information.

JavaScript libraries and tests

JavaScript Library:

Many standard scripts are available on specialised websites. These usually need additional configuration and customisation and you should always check browser compatibility. Pay attention to copyright restrictions.

JavaScript Test:

You may encounter browser incompatibility when implementing JavaScript. What works on one browser won't automatically work on another. When running tests, you should make sure your browser is configured to display all error messages.

Interactivity with Java and JavaScript

For interactivity, Java is mostly used to create little interactive elements in web pages – like navigation tools involving actions triggered by the user, mouse-over image changes, sound effects and the possibility to add interactive features. Applets can be used for all kinds of things: calculators, calendars, clocks, text effects, scrolling banners, games, etc.

Java-compatible browsers are a must to make the most of the possibilities offered by interactivity. Accordingly, on EUROPA you must offer alternative means of providing the same functionalities for browsers that don't work with Java.

 
 

Validation tools

 

Guidelines and references

 
 

Training

Please consult SyslogRestricted area: This link points to internal pages and may not work if you are browsing as an external user., the training information system, which gives you access to the training catalogue, the training map and allows you to introduce your application for a training course.