mercredi 22 août 2012

Basic JavaScript - Web programming

This post corresponds to notes taken while reading Eloquent JavaScript.

The open method of the window object takes an URL argument that will open on a new window. An opened window can be closed with its close method. To escape unwanted characters in the URL (e.g. space), the encodeURIComponent method can be used. To remove them again use decodeURIComponent method.
Every window object has a document property that contains the document shown in that window. To force the browser to load another document, someone can set the document.location.href property.
var perry ="");
// show some information about the URL of the document
// encoding URL
var encoded = encodeURIComponent("aztec empire");
The document object has a property named forms which contains links to all the forms in the document. Example, if a form has a property name="userinfo" then it can be accessed as a propery named userinfo.
The object for the form tag has a property elements that refers to an object containing the fields of the form by their name.
var userForm = document.forms.userinfo;
// set the content (via the value property) of a text input element called 'name'
var nameField =;
nameField.value = "Eugène";

Aucun commentaire:

Enregistrer un commentaire