Video tutorials from WebMagisters. Douglas Crockford "JavaScript: Strengths"

Selection of materials for learning JavaScript for any level of training - we have collected useful resources, which are suitable for both beginners and professionals.

Beginner Marijn Haverbeke "Expressive JavaScript"

The book touches on the fundamental concepts of not only JS, but programming in general. In addition to studying theory, the author will offer to implement several interesting practical projects. For example, create your own programming language.

JavaScript Jedi course from Sorax

Video course from famous programmer and a teacher named Sorax is great for starting to learn JS.

Video tutorials from WebMagisters

Another excellent video course in Russian that will tell you about the basics of JS and how to properly use it in web development.

JavaScript30

English-speaking 30-day practical course by JS. The author does not rely heavily on theory, but from the first lesson he suggests writing interesting projects, which become more difficult from lesson to lesson.

For those who know the basics Modern JavaScript tutorial

An interactive tutorial that will be equally useful to both a beginner and a programmer who has studied the basics. It contains many subtleties and tricks regarding the work of JS and DOM.

Eddie Osmani "Patterns for Scalable JavaScript Applications" JavaScript. Templates

This book is also a guide to a large number practical examples and a complete guide to basic concepts. Recommended for programmers who need to learn a web programming language, as well as programmers who already use JS and want to master it perfectly.

Douglas Crockford "JavaScript: strengths»

JS - far from it best language programming, especially when it comes to its optimization. Since it was created in a hurry, it has a lot weaknesses and terrible designs. This is exactly what the author proposes to talk about on the pages of his book, and at the same time understand what determines the strengths of the language and how this will help create truly extensible and effective code.

McLaughlin B. “Learning AJAX”

A book for those who want to better understand how AJAX works. Recommended for anyone who wants to take their creation to the next level interactive applications for the web.

Tom Coleman & Sasha Greif "Discover Meteor." Building Real-time JavaScript Web Apps"

The book is dedicated to Meteor.js - a framework that is built on the basis of Node.js and is essentially a fast layer between the interface and the database. It allows you to create truly interactive JS applications and use a single code on both the server and the client.

Meteor.js Documentation

Meteor.js documentation translated by the community into Russian.

Mark Bates "CoffeeScript. JavaScript's second wind"

If you already know and use CoffeeScript in your work, then this book will help you do your job better. And if not, it will be an excellent guide and the main reference book on the topic. The publication is intended primarily for web developers using JS, as well as all those who want to write high-quality and understandable code.

Maximiliano Firtman “jQuery Mobile. Development of applications for smartphones and tablets"

The book talks about creating dynamic web applications using JS, AJAX and jQuery libraries. It also pays attention to the creation of applications with the ability to work autonomously offline.

We have collected several excellent guides on the Internet for working and learning Angular.js and present them to your attention.

Continuation of the selection of materials on Angular, this time with links to various useful sources, such as the presentation of the framework version 2 (to find out what has changed and appeared in new version framework from the original source), as well as interesting podcasts and other materials that may be useful in learning Angular.js.

Video tutorials on Node.js

A short video course on Node.js - suitable for those who are completely unfamiliar with this framework and for those who want to refresh their knowledge about it.

Video tutorials on CoffeeScript from Sorax.

Another series of tutorials from Sorax, this time for more advanced JS users who want to get familiar with CoffeeScript. Great to watch right after the vanilla JavaScript course.

Book "Surrealism in JavaScript".

An excellent guide for those who like to learn new things through practice - the book will tell you how to create complex applications such as games using JS.

At a Glance: In Part 1 of the Modern JavaScript Concepts Handbook series, we'll introduce functional programming (FP), reactive programming (RP), and functional reactive programming (FRP). To do this, we will learn about purity, state and statelessness, immutability and mutability, imperative and declarative programming, higher order functions, observables and the FP, RP, FRP paradigms.

Introduction

Behind last years JavaScript has evolved a lot and doesn't think it will stop there. However, many concepts born in JS blogs and documentation remain unclaimed by a wide range of interface developers. In this series of articles, we'll explore concepts that require both intermediate and advanced levels of knowledge, and how they fit into modern JavaScript.

Concepts

In this article, we'll cover concepts that are critical to understanding functional programming, reactive programming, and functional reactive programming and how to use them with JavaScript:

  • Purity: pure functions, impure functions, side effects
  • Condition: with and without it
  • Immutability and changeability
  • Imperative and declarative programming
  • Higher Order Functions
  • Functional programming
  • Observables: hot and cold
  • Reactive Programming
  • Functional Reactive Programming
Purity Pure functions

The return value of a pure function depends only on its input data (arguments) and does not entail any side effects. With the same input argument, the result will always be the same. Example:

Function half(x) (
return x / 2;
}

The half(x) function takes a number x and returns the value of half x . If we pass an argument of 8 to this function, it will return 4. Once called, a pure function can always be replaced by the result of its work. For example, we could replace half(8) with 4: wherever this function is used in our code, the substitution would have no effect final result. This is called referential transparency.

Pure functions depend only on what is passed to them. For example, a pure function cannot reference variables in its parent's scope unless they are explicitly passed to it as arguments. Even then, the function cannot change anything in its parent scope.

Var someNum = 8;

// this is NOT a pure function
function impureHalf() (
return someNum / 2;
}

  • Pure functions must take arguments.
  • The same inputs (arguments) will always produce the same outputs (return the same result).
  • Pure functions are based only on the internal state and do not change the external one ( note: console.log changes global state).
  • Pure functions do not produce side effects.
  • Pure functions cannot call impure functions.
Impure functions

An impure function changes state outside its scope. Any functions with side effects(see below) are unclean, just like procedural functions without a return value.

Consider the following examples:

Side effects in JavaScript

When a function or expression changes state outside of its context, the result is a side effect. Examples of side effects: calling an API, manipulating the DOM, outputting an alert, writing to a database, and so on. If a function produces side effects, it is considered unclean. Functions that cause side effects are less predictable and harder to test because they cause changes outside their local scope.

To sum it up: cleanliness

A lot of good code consists of impure functions procedurally called by pure ones. This still has a lot of benefits for testing and immutability. Referential transparency also has the convenience of memoization: caching and storing the results of function calls, and then reusing the cached results. However, determining when functions are truly pure can be difficult.

Additional information on cleanliness can be found in the following resources:

  • Pure or impure functions
  • Functional Programming: Pure Functions
State

State — information that a program has access to and can work with at a certain point in time. This includes data stored in memory, I/O ports, databases, and so on. For example, the contents of variables in an application in any this moment time is representative of the state of the application.

With a fortune

Stateful programs, applications, or components store current state data in memory. They can change the state and also have access to its history. The following example demonstrates this:

Var number = 1;
function increment() (
return number++;
) // global variable is changed: number = 2

increment();

No state

Stateless functions or components perform tasks as if they were being run for the first time each time. They do not reference or use previously created data in their execution. Statelessness provides referential transparency. Functions depend only on their arguments and do not have access to or need to know anything outside their scope. Pure functions have no state. Example:
Var number = 1;
function increment(n) (
return n + 1;

Stateless applications still manage state. However, they return to their current state without changing the previous state. This is the principle of functional programming.

To sum it up: condition

Wealth management is important for anyone complex application. Stateful functions or components change the state and its history and are more difficult to test and debug. Stateless functions rely only on their inputs to produce outputs. A stateless program returns new state rather than modifying existing state.

Additional status information can be found at the following resources:

  • State
  • Benefits of Stateless Programming
  • Components with and without states, missing manual
  • Redux: Predictable State Container for JavaScript Applications
Immutability and changeability

The concepts of immutability and mutability are more nebulous in JavaScript than in some other programming languages. However, you will hear a lot about immutability when reading about functional programming in JS. It's important to know what these terms mean in a classical sense and how they are implemented in JavaScript. The definitions are quite simple:

Immutable

If an object is immutable, its value cannot be changed after it is created.

Changeable

If an object is mutable, its value can be changed after creation.

Implementation: Immutability and Mutability in JavaScript

IN JavaScript strings and numeric literals are implemented immutable. This is easy to understand if we consider how we work with them:

Var str = "Hello!";
var anotherStr = str.substring(2);
// result: str = "Hello!" (not changed)
// result: anotherStr = "llo!" (new line)

Using the .substring() method on our Hello! , the string does not change the original string. Instead she creates new line. We could redefine the value of str to something else, but once we've created our Hello! , it will forever remain Hello! .

Numeric literals are also immutable. The following example will always have the same result:

Var three = 1 + 2;
// result: three = 3

Under no circumstances can 1 + 2 become anything other than 3.

This demonstrates that JavaScript has an implementation of immutability. However, JS developers know that the language allows you to change a lot. For example, objects and arrays are mutable. Consider the following example:

Var arr = ;
arr.push(4);
// result: arr =

var obj = ( greeting: "Hello" );
obj.name = "Jon";
// result: obj = ( greeting: "Hello", name: "Jon" )

In these examples source objects changed. New objects are not returned.

To learn more about mutableness in other languages, check out Mutable and Immutable Objects.

In Practice: Mutability in JavaScript

Functional programming in JavaScript is growing well. But at its core, JS is a highly fluid language, consisting of many paradigms. Key Feature functional programming — immutability. Other functional languages will throw an error when a developer tries to change an immutable object. Then how can we reconcile the inherent mutability of JS when writing functional or functional reactive JS?

When we talk about functional programming in JS, the word "immutable" is used a lot, but it is the responsibility of the developer to always keep it in mind. For example, Redux relies on a single immutable state tree. However, JavaScript itself is capable of modifying the state object. To implement an immutable state tree, we need to return a new state object every time the state changes.

To demonstrate the concept of observables, let's look at a simple example: resizing a browser window. In this context, observables are as clear as possible. Browser window resizing emits a stream of events during certain period time (while the window is receiving right size). We can create an observable and subscribe to it to respond to a stream of resize events:

The code example above demonstrates that as the window size changes, we can limit the observable stream and subscribe to its changes to respond to new values ​​in the collection. This is an example of a hot observable.


About this guide

The reference book is intended for people who have already mastered the basics of programming in JavaScript.

The directory was created on the basis of information provided on the website “Directory of Web Languages” www.spravkaweb.ru.


Due to this resource constantly replenished new information, download updated version reference book can be found in the Download section




Also on the site, reference books on PHP, CSS, Perl, MySQL are available for download.



A joint using HTML and JavaScript

. . . Script text

Attribute language

Second attribute src

turns into single:

.

Tag


Rules for writing scripts

First of all, we need to consider the tag. This tag is used to insert scripts into the HTML code of the page. Its format:

. . . Script text

The script text is placed inside the tag

Attribute language allows you to specify in which programming language the script is written.

The default value is "JavaScript".

Internet Explorer scripts written in VBScript language, which corresponds to the value of the "VBScript" attribute.

Navigator allows you to set the JavaScript interpreter version:

This can come in handy in cases where you use the option JavaScript language, specific to a particular version.

The following table shows the versions of the JavaScript interpreter and their correspondence different versions Navigator:

Second attribute src serves to specify the address of the file containing the script.

In this case, usually the paired tag turns into a single tag:

js- standard extension for JavaScript files.

But what happens if the Web browser does not support scripts? (For example, it's too old version program, or the user has disabled script support in the security settings.) The Web browser will ignore the tag and display the script text.

To avoid this, it is recommended to enclose the script inside a tag in a comment.

However, some versions of Navigator do not “see” the script in this case, although, according to technical manuals Netscape itself should. So this tip only applies to Internet Explorer.

Alternatively you can use the .

This tag is supported by Internet Explorer and Navigator:

. . . Text to display if the Web browser does not support scripts

The tag can be placed anywhere in the text of the page, even outside the . Text placed inside this tag will be displayed instead of the entire page. That is, a user of a Web browser with script support disabled will see only this text in the window and nothing else.


Document object model

It should be noted that JavaScript supports so-called external classes and objects defined by other programs. The Web page that you view in a Web browser window can be described as a collection of objects. Let's say it includes large object"document-as-a-whole" and smaller objects: "paragraph-1", "paragraph-2", "paragraph-1" and "figure". You can access these objects from the same JavaScript.

Figure.MoveForward;Paragraph-1.Width = 80%;Paragraph-3.Show;

Of course, this is being greatly exaggerated, but the principle is this.

For example, consider the script:

var d;d=new Date();document.write(d.toString());

Document document- this is our “document-as-a-whole”. A write- its method that inserts the text passed as a parameter into the current location of the HTML document.

The collection of objects that describes a web page, with all their methods and properties, is called the document object model. A technology for creating a web page, in which regular HTML code is combined with JavaScript code, and the latter controls the page using object model, is called dynamic HTML (DHTML).


document object

activeElement



alinkColor




Example:










characterSet



compatMode



defaultCharset



designMode



documentElement









fileCreatedDate



fileModifiedDate



fileSize










edocument.images


lastModified





linkColor





location





parentWindow




Similar to document.embeds


protocol



readState



referrer





security



selection



styleSheets







URLUnencoded



vlinkColor




The width of the document in pixels.


Properties

First of all, it should be noted that the document object exists in a single instance for the entire HTML document. It is always present if an HTML document exists, so there is no need to create it specifically.


activeElement



alinkColor


Sets or returns the color of active hyperlinks.

document.alinkColor[="(Color)"];



Anchor objects are expressions in HTML document, described in the descriptor. These objects are indicated in the URL by the # symbol located between the page URL and the anchor name.

Example: Getting the number of anchors in a document

var anchorCount=document.anchors.length



The applet property allows you to access java applets contained in a document.



Sets or returns the page background color. In IE it works correctly only if the page color is set to the BGCOLOR attribute.



This object has many key properties to control the appearance of the page. To access its properties, it is better to use the document.body expression.



This property sets the encoding used by the browser to display the current page. Only IE is used.


characterSet


This property sets the encoding used by the browser to display the current page. Only NN is used.


compatMode


Internet Explorer 6 introduced a new property of the document object called compatMode. Thanks to this property (it is read-only, by the way), we can determine which mode is currently enabled - BackCompat (IE 4.x–IE 5.x) or CSS1Compat (IE 6). Based on the value of this property, we can, for example, specify different values CSS properties width, margin or padding:

if (document.getElementById)(oBlock = document.getElementById("mydiv");oBlock.style.width = ((document.compatMode) && (document.compatMode == "CSS1Compat")) ? "200px" : "250px" ;)


defaultCharset


This property sets the encoding used by the browser to display the current page. There is no difference between charset and defaultCharset, but if you temporarily change the charset property in a script, you can use defaultCharset to restore the original character set.


designMode


This property is used when the IE browser acts as a component of another application, this situation described here. It allows/prohibits changing the HTML code of the current page; under normal conditions, this property has no effect.


documentElement




Whenever it is necessary to load data that requires an application plug-in to play it or display it on the screen, use the descriptor The document.embeds property is the only way to determine such descriptors added to the document

var count=document.embeds.length



This property, when set to true, allows the use of new object properties that you added when executing the script.



Sets or returns the text color. Default value is #000000.


fileCreatedDate


Returns the creation date of the HTML document file in mm/dd/yyyy format, read-only.


fileModifiedDate


Returns the date last change HTML document file in mm/dd/yyyy format, read-only.


fileSize


Returns the file size of an HTML document or graphic image.



Returns an array of form objects. The first element of the document.forms array is a link to the very first form defined in the document.



Returns an array of frame objects. The first element of the document.frames array is a reference to the very first frame defined in the document.



Sets or returns the height of the current window or frame in pixels, corresponding to the IE scrollHeight property.



edocument.images


lastModified


Returns the date the document was last modified as a string.



This is an array of layers located in the document


linkColor


Sets or returns the color of hyperlinks in a document. In IE it works correctly only if the color of the gypsum links is set by the LINK attribute.




location


Installing a new URL addresses location property will load the page located at this address



Read-only property, returns the address of the currently loaded page in the browser.


parentWindow


The document.parentWindow property returns a reference to the window object that contains the current document.



Similar to document.embeds


protocol


Returns the protocol version used to access the current document


readState


Returns the current state of the document.


referrer


Returns the Internet address of the Web page from which the user navigated to current page. If the user navigates to it by simply typing the address in the Web browser, an empty string is returned.



Returns an array of all SCRIPT elements contained in the document. It is possible not only to view the array, but also to add/remove elements.


security


This property provides information about the type of security, if any, applied in the current document.


selection


The document.selection property returns a selection object, the contents of which are displayed in the browser window as a selection of body text. This selection can be done by the user or by script in a TextRange object


styleSheets




Returns the title of the Web page specified in the tag



Sets or returns the Internet address of the current Web page.


URLUnencoded


The property returns the URL string as code. This means that all non-alphanumeric characters (meaning only numbers and letters of the Latin alphabet) will be recoded into their URL representation. i.e. the % sign and hexadecimal code character (for example, a space will look like %20).


vlinkColor


Sets or returns the color of visited hyperlinks in a document. In IE it works correctly only if the color of visited hyperlinks is set to the VLINK attribute.



The width of the document in pixels.


Methods

This method is designed to clear the current document from the browser window.



Causes a Web page to immediately update its content after using the write methods. The method does not accept parameters and does not return a value.


createAttribute()


createAttribute("Attribute Name")

Generates an attribute object and returns a reference to it. When calling the method, only the name of the attribute is specified, so the script assigns a value to the nodeValue property, and then the new attribute is added to the existing element using the *Returns: attribute object reference


setAttributeNode


var newAttr = document.createAttribute("width");newAttr.nodeValue = "80%";document.getElementById("myTable").setAttributeNode(newAttr);


createElement()


createElement("Handle name")

Generates an attribute object for any HTML (or XML) descriptor specified as a parameter. This object is not officially part of the current document's object model, since it is not yet part of the document. But this method used to call the element object that will eventually be placed in the document.


elementFromPoint()


elementFromPoint((X), (Y))


getElementById()


getElementById((Element name))

Returns the element whose name is passed as a parameter. The page element name is specified by the ID attribute. The method takes a single parameter - the name of the page element.


getSelection()


Returns a string containing text selected by the user on the page. The method does not accept parameters.



write((Text))

Writes the text or HTML code passed as a parameter to the current location in the document.


writeLn()


writeLn((Text))

Same as write, but adds a carriage return and line feed at the end.


Collection of objects

Collection is a kind of array of objects, indexed not only by the numeric numbers of the elements, but also by their names, and having properties and methods. The collection is different from associative array precisely by the presence of properties and methods, i.e. a collection is an object in itself.

Consider, for example, the images collection that the document object includes. You can access its individual elements by serial number or unique name.

document.images.item(1)document.images("iamge1")

Note that we indicate the index of the collection element not in squares, but in parentheses because it is actually an argument to the item method function supported by all collections. The name of this method can be omitted.

document.images(1)document.images("image1")

All elements of a Web page are numbered in the order they appear in the HTML code. And unique names are specified by a special attribute ID, available in almost all tags.

For some tags (in particular and ) is also available NAME attribute, which performs the same function as ID.

The all collection represents all elements of a Web page, without exception, including images. Elements of this collection can be referred to by number (they are numbered in the order they appear in the HTML code) or by name.

document.all(8)document.all("iamge1")

The ID attribute requires the names of all elements to be unique, but only formally. In reality, there may be two or more elements on the page with same names. In this case, you will need to specify a second index

document.all("image1", 2)

or expression document.all("image1") will return a collection of all images named image1.

Also, all collections have a length property, which specifies the number of elements in the collection. It should be noted that the elements of the collection are numbered from zero, so its last element will have the number length-1.

Some collections may have methods for adding and removing elements and other purposes.


Subordinate objects and collections of the document object

The document object contains many subordinate objects and collections within it. The following table lists the properties that return references to them and provides descriptions of the corresponding objects and collections.

Collection all It has additional method tags, which allows you to filter collection items by their tag. This method takes the string value of the desired tag as a parameter.

document.all.tags("H1")

The same method is supported by the collection links.

I also want to mention two methods supported by Internet Explorer since 5.0. These are the methods getElementByName And getElementByTagName. The first one returns a collection of elements with the attribute value NAME passed as a parameter. Since the attribute NAME used in modern HTML very rarely, the benefit of this method is small. The second method returns a collection of elements created by the tag passed as a parameter.

document.getElementByName("someimage") document.getElementByTagName("H1")


Accessing Page Elements

An object document has several useful methods that can be used in scripts. But its main significance is providing access to individual elements of a Web page. How can you get to an individual element of a page? First of all, through collections. For example, a collection all:

document.all("image1").outerHTML

Or through the collection images:

document.images("image1").outerHTML

all("image1").outerHTMLimages("image1").outerHTML

NN doesn't allow you to do that. It requires a mandatory link to document. In addition, it does not support the collection all.

document.images("image2").src

The name of a Web page element is specified using attributes ID And NAME. If every page element has unique name, then you can use the so-called direct appeal to the elements. That is, access it not as an element of the collection, but as separate object. This works in both IE and NN.

image1.outerHTMLlayer1.top

Direct access is faster than access through a collection. Therefore, it is recommended to use it in all cases where special access to collections is not needed and when each page element accessed from scripts has a unique name.


location object

An object location contains information about the location of the current document, i.e. his internet address. It can also be used to move to another document and reload the current document.


Properties of the location object



Location object methods


Using the location object, you can load another document in place of the current one. To do this, simply assign the value of the new Internet address to the property href.

document.location.href = "http://www.spravkaweb.ru";

IE users can also use the method assign:

document.location.assign("http://www.spravkaweb.ru");

If you want to completely replace the current document so that even its address does not appear in the history list, use the method replace:

document.location.replace("http://www.spravkaweb.ru");


style object

Like all other objects, style

style style


Properties and Methods

Like all other objects, style supports a number of properties and methods. They can be divided into two groups:

The properties of the first group are generally similar to the corresponding style attributes and have almost the same names, with the exception that the "-" symbols are removed, because do not follow JavaScript naming conventions, and the first letters of all words that make up the attribute name except the first are capitalized. The following table shows examples of converting style attribute names to names of style object properties that set the element's style.

By analogy, you can convert all style attributes into properties of the style object. All non-style properties of the style object are listed in the table below. This object also has getAttribute, removeAttribute, and setAttribute methods. But these additional properties and methods are only supported by IE starting from 4.0


Working with the style object

The style object allows you to change the style of any element on a Web page by simply assigning the desired property required value.

paragraph1.style.fontSize = 7;

You can change the geometric dimensions of an element:

image1.style.height = "100mm";image1.style.width = "120mm";

and its location:

iamge1.style.top = "200px";image1.style.left = "50px";

Notice that we assign the property string values ​​of the geometric parameters, indicating the unit of measurement. This is not very computationally friendly, so the style object provides properties pixel, receiving and returning numeric values in pixels:

image1.style.pixelHeight = 400;iamge1.style.pixelLeft +=5;

You can also use properties pos, which return and accept numeric values ​​in the units in which these values ​​were specified in the style definition.

nheight = image1.style.posHeight; // Value in millimetersnwidth = image1.style.posWidth; // Value in pixels

You can use methods getAttribute, setAttribute And removeAttribute to get and set the value and remove any style property:

paragraph1.style.setAttribute("borderBottomWidth", 5, false);paragraph1.style.removeAttribute("borderTopWidth", false);


The style object in Internet Explorer

How do you access the style object? Internet Explorer provides three properties for this: style, currentStyle And runtimeStyle.

The first property allows you to access the style embedded in the element tag using the STYLE attribute:

Any text

someColor = par1.style.color;

The above expression will put into a variable someColor attribute value color inline element style, i.e. "green".

someFontSize = par1.style.fontSize;

This expression will return null, even if somewhere in the style sheet the attribute font-size defined for this element. And all because the interests of the style property do not go beyond the built-in city.

To get an element's style taking into account both inline styles, style sheets, and tag attributes, use the property currentStyle:

Any textsomeColor = par1.currentStyle.color;someBColor = par1.currentStyle.backgroundColor;someFontSize = par1.currentStyle.fontSize;someOther = par1.currentStyle.textDecoration;

Let's assume that somewhere in the style sheet there is an attribute defined for this element background-color, equal to "teal", and text-decoration not defined at all. These expressions will return the following values: the first is "green", the second is "teal", the third is "largest" (or "7"), and the fourth is "none"? those. The default value for this style attribute.

If you change any property of the style object, the same property of the currentStyle object will change, and vice versa. The only detail: if you change any currentStyle property and then immediately access it, the old value will be returned. That is, some time must pass between assigning a value and applying it to the element.

Property runtimeStyle quite strange. It returns a reference to the object runtimeStyle, which is roughly the same as currentStyle, but assigning new values ​​to its properties does not affect the similar style properties. That is, you can override the style properties runtimeStyle, and the corresponding style properties (but not currentStyle) will not change.


styleSheet object and styleSheets collection


The IE document object has a built-in styleSheets collection that you can use to access individual document style sheets. A separate table styles are represented by a styleSheet object:

address = document.styleSheets(1).href;

Three properties of the style sheet object will be useful to us.

The first one is href, representing the Internet address of the external style sheet file. You can change this URL to load a different style sheet.

Second - disabled, which allows or prevents the Web browser from using this table to format the document. Please note that in in this case false allows the table to be used, and true disables it.

And the last property - type- is of only theoretical interest to us: it specifies the stylesheet type, which for IE is always "text/css".


The style object in the Navigator. JavaScript styles

Navigator supports direct reference by identifiers only for layer objects and does not support collections all. Yes and attribute support ID it is implemented so-so, mainly for assigning styles to elements. But the object document Navigator provides four very powerful properties for working with styles.

Property classes will allow you to access a separate named style:

document.classes.(Style name).(Tag name)|all.(Property name)

Here (Tag Name) can be the name of any tag. If you need to define a style for all tags, use the word all.

For example, suppose you define a style in your style sheet:

Somestyle (color: green)

Then in the script code you can access it:

document.classes.somestyle.all.fontFamily = "Arial";

Similarly, you can define a style for one specific tag:

P.somestyle (color: green)document.classes.somestyle.P.fontFamily = "Arial";

In turn, the ids property will allow you to access the style assigned to a particular ID:

document.ids.(Identifier).(Property name)

For example:

#someid (color: green)document.ids.someid.fontFamily = "Arial";

But what if you override the style of a tag? In this case, use the property tags:

document.tags.(tag).(Property name)

For example:

H1 (color: green)document.tags.H1.fontFamily = "Courier";

What if you need to, say, change the style of an element located inside a second-level heading? There is a property for this contextual:

document.contextual((Context 1)[, (Context 2)[, ...]]).(Property name)

Then for the case we described:

document.contextual(document.tags.H2, document.tags.B).fontStyle= "oblique";

which is similar to specifying in a style sheet

H2 B (font-style: oblique)

But if you think you can dynamically change the appearance of page elements in Navigator by changing their styles, you are sadly mistaken. In reality, the style object is needed by Navigator only to support a new type of style sheet, the so-called JavaScript styles.

JavaScript styles differ from regular styles in that they are most similar to scripts. Actually, these are scripts. Let's look at two examples: a regular style sheet and a JavaScript style sheet:

P (color: blue).bigtext (font-size: 72pt; font-weight: boldest)H1 B (text-decoration: underline)

This is a regular style sheet. Now let's convert it into a JavaScript style sheet:

document.tags.P.color = "blue";width (document.classes.bigtext.all) ( fontSize = "72pt"; fontWeight = "boldest"; )document.contextual(document.tags.H1, document.tags. B).textDecoration = "underline";

Now you can see how a JavaScript style sheet is similar to a script. Note also that in this case the attribute type required, because it specifies the type of style sheet.

In all previous examples for Navigator, we always provided a reference to the object document. But it can be omitted in JavaScript style sheets.

tags.P.color = "blue";width (classes.bigtext.all) ( fontSize = "72pt"; fontWeight = "boldest"; )contextual(tags.H1, tags.B).textDecoration = "underline";


window object

The window object represents the current Web browser window, or an individual frame if the window is divided into frames.



Returns true if the current window is closed. Can be used when working with multiple windows.


defaultStatus


The default message displayed in the window's status bar.


document







innerHeight


Returns the height of the window's client area (without borders, menus, toolbars) in pixels.


innerWidth


Returns the width of the window's client area (without borders, menus, toolbars) in pixels.

Only NN is supported starting from 4.0



Returns the number of frames.


location



locationbar


Returns a reference to the Navigator window's address bar object (aka Location Toolbar). The only property of this object, visible, will allow you to show it or hide it; the value true of this property shows the address bar, false removes it.

Only NN is supported starting from 4.0



Only NN is supported starting from 4.0



Returns the name of the window or frame.


navigator





outerHeight


Returns the total height of the window (with borders, menus, toolbars) in pixels.

Only NN is supported starting from 4.0


outerWidth


Returns the full width of the window (with borders, menus, toolbars) in pixels.

Only NN is supported starting from 4.0


pageXOffset


Returns the horizontal distance between the current window position and the left border of the document. When scrolling the contents of the window to the right, the value of this property increases, and to the left - decreases.

Only NN is supported starting from 4.0


pageYOffset


Returns the vertical distance between the current window position and the left border of the document. When scrolling the contents of the window down, the value of this property increases, and when scrolling up, it decreases.

Only NN is supported starting from 4.0




personalbar


Only Navigator from 4.0 is supported




screenLeft


Returns the horizontal coordinate of the left top corner window.


screenTop


Returns the vertical coordinate of the upper left corner of the window.

Only IE 5.0 and above is supported



Horizontal coordinate of the upper left corner of the window.

Only NN is supported starting from 4.0



The vertical coordinate of the upper left corner of the window.

Only NN is supported starting from 4.0


scrollbars


Only NN is supported starting from 4.0





The text that appears in the status bar of a Web browser window.


statusbar


Only NN is supported starting from 4.0



Only NN is supported starting from 4.0