How to set up smartphones and PCs. Informational portal
  • home
  • Reviews
  • A short description of javascript and its capabilities. How to enable JavaScript and what is JavaScript error

A short description of javascript and its capabilities. How to enable JavaScript and what is JavaScript error

In this article we will tell you what JavaScript (Java Script) is, give examples, explain why it is needed in the html code. We will give answers to popular questions webmasters.

1. What is JavaScript in simple words

JavaScript(in Russian "Java Script", abbreviated "JS") is a programming language embedded in HTML pages for the purpose of convenience of communication with the user, error handling and creation of dynamism for the page as a whole.

JavaScript is an object-oriented and interpreted language. It is system independent (works on any platform). JS code is often called scripts. We can say that this language is "sharpened" only for web programming.

The syntax of the language is much like C and Java, semantically, the language is much closer to Self, Smalltalk.

2. Tasks solved by JavaScript

  • Validation of html form fields (tag
    ) before they are sent to the server
  • Information messages with warnings
  • Effects for highlighting main elements and parts of the page
  • Original dropdown menus
  • Math calculations

Usually with using Java Script make sliders. You can also display content through AJAX output, this allows you to hide unnecessary or duplicate elements of the site page from the html-code. It makes no sense for a beginner to study these codes, since they are quite complex.

3. How to enable JavaScript support in the browser

All browsers support JavaScript. By default Java Script should already be enabled in browsers, if not, then below are instructions for different browsers to include JS.

1. Enable JavaScript in Firefox 2. Enable JavaScript in Google chrome

"Customization and google management Chrome "->" Options "->" Advanced "->" Privacy (Content Settings) "->" JavaScript: "Allow all sites to use JavaScript (recommended) or deny JavaScript execution on all sites

3. Enable JavaScript in Opera

Press the F12 key Select "Enable JavaScript"

4. Enable JavaScript in Internet Explorer

"Service" -> "Internet Options" -> "Security" tab -> select the "Internet" zone -> "Other" button -> "Scripts" item -> "Allow scripts"

4. Example: how to insert JavaScript into an html page

JavaScript code fits right into the html code of the page. To highlight it, use special tags.

Атрибут type="text/javascript" указывать не обязательно, но желательно.

Использовать <script> can be in header tags , and just in the body of the page .

Write html tags between opening and closing script tag is prohibited. This place is for JavaScript code only.

In order not to duplicate the same JavaScript on each page, it is usually carried out in separate file with the extension ".js". This file can be connected anywhere in the html page.

4.1. Пример 1. Всплывающие сообщение Hello, World

Ниже представлен пример html код, который при загрузке страницы выводит всплывающее сообщение "Hello, World".

Hello, World на JavaScript

Пример с Alert. Будет выведено всплывающие сообщение


Нажмите на ссылку:

Перейти по ссылке? ");">Ссылка

4.2. Пример 2. Альтернатива с обработкой javascript

Ниже представлен пример html кода с обработкой кода JavaScript с помощью идентификатора id.

Hello, World на JavaScript

Нажмите на ссылку :

Ссылка

4.3. Пример 3. Смена цвета объекта при наведении курсора

При наведении курсора мышки на определенные области, они изменяют цвет. Делается это через JavaScript. Например

Код этого примера:

RED
GREEN
BLUE

Это лишь самые элементарные вещи на JavaScript. Его возможности довольно большие. Не даром в литературных магазинах по этому языку можно найти отдельные книги.

JavaScript- это язык программирования, позволяющий создавать скрипты, которые встраиваются в HTML-страницы и выполняются в браузере посетителя страницы.

Современные браузеры в обязательном порядке имеют поддержку языка JavaScript.

Команды JavaScript добавляются на веб-страницы с помощью тега

Attribute type tag.

Mastering the JavaScript language, you must first of all master the comments, which should be used especially often at the beginning of using the language.

JavaScript allows short comments- comments, the length of which does not exceed the length of the line. Everything after two characters // to the end of the line will be a short comment. Here are two examples of short comments:

// 1. The command below displays the Paragraph in bold
document. write ( «» );

document. write ( Hello, World! ); // 2. Output in italics the string Hello, World!

Additionally, JavaScript allows multiline comments- comments that span multiple lines. Here's an example of such a comment:

/*
The first command displays the paragraph in bold,
and the second command displays the paragraph in italics
*/
document. write ( «

Bold paragraph.

» ); document. write ( «

Italicized paragraph.

»
);

It is impossible to describe all the features of the JavaScript language on one page, on it I will write only the most essential, in my opinion, features of the language.

The script of this language can be either embedded directly into the HTML code of the page, or transferred to a file that can be called different pages... Here is an example of calling a file with a script:

<script type = "text / javascript" src = "Http: // Path_to_file_with_script">

If the src = "..." attribute is specified, then the content of the tag is ignored, that is, in one script tag you cannot connect an external script and specify the code at the same time, so you need to choose: script either contains src, or contains code. If necessary, we just add the code to another script.

By the way, WordPress versions 4.0 does not recognize the code JavaScript in the HTML code of the pages and spoils it by hiding the code JavaScript perdocument.write("");

Top related articles