You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/01-hello-world/2-hello-alert-ext/task.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,8 +2,8 @@ importance: 5
2
2
3
3
---
4
4
5
-
# Show an alert with an external script
5
+
# Afișați o alertă cu un script extern
6
6
7
-
Take the solution of the previous task <info:task/hello-alert>. Modify it by extracting the script content into an external file `alert.js`, residing in the same folder.
7
+
Luați soluția sarcinii anterioare <info:task/hello-alert>. Modificați-o extrăgând conținutul script-ului într-un fișier extern `alert.js`, cu reședința în același folder.
8
8
9
-
Open the page, ensure that the alert works.
9
+
Deschideți pagina, asigurați-vă că funcționează alerta.
This part of the tutorial is about core JavaScript, the language itself.
3
+
Această parte a tutorialului este despre JavaScript de bază, limbajul în sine.
4
4
5
-
But we need a working environment to run our scripts and, since this book is online, the browser is a good choice. We'll keep the amount of browser-specific commands (like`alert`) to a minimum so that you don't spend time on them if you plan to concentrate on another environment (like Node.js). We'll focus on JavaScript in the browser in the [next part](/ui)of the tutorial.
5
+
Dar avem nevoie de un mediu pentru a rula script-urile și, având în vedere că această carte este online, browser-ul este o alegere bună. Nu o să folosim prea multe comenzi specifice browser-ului (ca`alert`) ca să nu pierdeți prea mult timp cu ele dacă vreți sa vă concentrați pe un alt mediu (ca Node.js). O să ne concentrăm pe JavaScript în browser în [urmatoarea parte](/ui)a tutorialului.
6
6
7
-
So first, let's see how we attach a script to a webpage. For server-side environments (like Node.js), you can execute the script with a command like`"node my.js"`.
7
+
În primul rând, haideți să vedem cum atașăm un script unei pagini web. Pentru mediile de dezvoltare de tipul server (ca și Node.js), se poate executa script-ul cu o comandă precum`"node my.js"`.
8
8
9
+
## Tag-ul "script"
9
10
10
-
## The "script" tag
11
+
Programele JavaScript pot fi inserate în orice parte al unui document HTML cu ajutorul tag-ului `<script>`.
11
12
12
-
JavaScript programs can be inserted almost anywhere into an HTML document using the `<script>` tag.
13
-
14
-
For instance:
13
+
feature/hello-world
14
+
De exemplu:
15
15
16
16
```html run height=100
17
17
<!DOCTYPE HTML>
18
18
<html>
19
19
20
20
<body>
21
21
22
-
<p>Before the script...</p>
22
+
<p>Înainte de script...</p>
23
23
24
24
*!*
25
25
<script>
26
26
alert( 'Hello, world!' );
27
27
</script>
28
28
*/!*
29
29
30
-
<p>...After the script.</p>
30
+
<p>...După script.</p>
31
31
32
32
</body>
33
33
34
34
</html>
35
35
```
36
36
37
37
```online
38
-
You can run the example by clicking the "Play" button in the right-top corner of the box above.
38
+
Puteți rula exemplul dând click pe butonul „Play” din colțul din dreapta-sus al căsuței de mai sus.
39
39
```
40
40
41
-
The `<script>` tag contains JavaScript code which is automatically executed when the browser processes the tag.
42
-
41
+
Tag-ul `<script>` conține cod JavaScript care este executat automat cand browser-ul procesează tag-ul.
43
42
44
-
## Modern markup
45
-
46
-
The `<script>` tag has a few attributes that are rarely used nowadays but can still be found in old code:
43
+
## Markup modern
47
44
45
+
Tag-ul `<script>` are câteva atribute care mai nou sunt folosite rar, dar care încă se găsesc în codul vechi:
48
46
The `type` attribute: <code><script <u>type</u>=...></code>
49
47
: The old HTML standard, HTML4, required a script to have a `type`. Usually it was `type="text/javascript"`. It's not required anymore. Also, the modern HTML standard totally changed the meaning of this attribute. Now, it can be used for JavaScript modules. But that's an advanced topic, we'll talk about modules in another part of the tutorial.
50
48
51
-
The `language` attribute: <code><script <u>language</u>=...></code>
52
-
: This attribute was meant to show the language of the script. This attribute no longer makes sense because JavaScript is the default language. There is no need to use it.
53
49
54
-
Comments before and after scripts.
55
-
: In really ancient books and guides, you may find comments inside `<script>` tags, like this:
: Acest atribut a fost menit să arate limbajul script-ului. Acest atribut nu mai are sens deoarece JavaScript este limbajul implicit. Nu este nevoie să îl folosiți.
52
+
53
+
Comentarii înainte și după script-uri.
54
+
: În cărțile și ghidurile foarte vechi, este posibil să găsiți comentarii în interiorul tag-urilor `<script>` în felul următor:
56
55
57
56
```html no-beautify
58
57
<script type="text/javascript"><!--
59
58
...
60
59
//--></script>
61
60
```
62
61
63
-
This trick isn't used in modern JavaScript. These comments hide JavaScript code from old browsers that didn't know how to process the `<script>` tag. Since browsers released in the last 15 years don't have this issue, this kind of comment can help you identify really old code.
64
62
63
+
This trick isn't used in modern JavaScript. These comments hide JavaScript code from old browsers that didn't know how to process the `<script>` tag. Since browsers released in the last 15 years don't have this issue, this kind of comment can help you identify really old code.
65
64
66
-
## External scripts
65
+
## Script-uri externe
67
66
68
-
If we have a lot of JavaScript code, we can put it into a separate file.
67
+
Dacă avem mult cod JavaScript, putem să îl punem într-un fișier separat.
69
68
70
-
Script files are attached to HTML with the `src` attribute:
69
+
Fișierele de acest tip sunt atașate codului HTML cu ajutorul atributului `src`:
71
70
72
71
```html
73
72
<scriptsrc="/path/to/script.js"></script>
74
73
```
75
74
76
-
Here, `/path/to/script.js` is an absolute path to the script from the site root. One can also provide a relative path from the current page. For instance, `src="script.js"`, just like `src="./script.js"`, would mean a file `"script.js"` in the current folder.
77
75
78
-
We can give a full URL as well. For instance:
76
+
Here, `/path/to/script.js` is an absolute path to the script from the site root. One can also provide a relative path from the current page. For instance, `src="script.js"`, just like `src="./script.js"`, would mean a file `"script.js"` in the current folder.
Pentru a atașa mai multe scripturi, utilizați mai multe tag-uri:
85
84
86
85
```html
87
86
<scriptsrc="/js/script1.js"></script>
@@ -90,29 +89,29 @@ To attach several scripts, use multiple tags:
90
89
```
91
90
92
91
```smart
93
-
As a rule, only the simplest scripts are put into HTML. More complex ones reside in separate files.
92
+
De regulă, doar cele mai simple script-uri sunt puse în HTML. Cele mai complexe se află în fișiere separate.
94
93
95
-
The benefit of a separate file is that the browser will download it and store it in its [cache](https://en.wikipedia.org/wiki/Web_cache).
94
+
Avantajul unui fișier separat este că browserul îl va descărca și îl va stoca în [cache](https://en.wikipedia.org/wiki/Web_cache).
96
95
97
-
Other pages that reference the same script will take it from the cache instead of downloading it, so the file is actually downloaded only once.
96
+
Alte pagini care fac referire la același script îl vor lua din cache în loc să-l descarce, astfel încât fișierul este descărcat efectiv o singură dată.
98
97
99
-
That reduces traffic and makes pages faster.
98
+
Aceasta reduce traficul și face paginile mai rapide.
100
99
```
101
100
102
-
````warn header="If`src`is set, the script content is ignored."
103
-
A single `<script>`tag can't have both the`src`attribute and code inside.
101
+
````warn header="Daca`src`este setat, conținutul scriptului este ignorat."
102
+
Un singur tag `<script>`nu poate avea atât atributul`src`cât și codul în interior.
104
103
105
-
This won't work:
104
+
Nu va funcționa:
106
105
107
106
```html
108
107
<script*!*src*/!*="file.js">
109
-
alert(1); //the content is ignored, because src is set
108
+
alert(1); //conținutul este ignorat pentru că src este setat
110
109
</script>
111
110
```
112
111
113
-
We must choose either an external `<script src="…">`or a regular`<script>`with code.
112
+
Trebuie să alegem fie un `<script src="…">`extern sau un`<script>`obișnuit cu cod.
114
113
115
-
The example above can be split into two scripts to work:
114
+
Exemplul de mai sus poate fi împărțit în două scripturi pentru a funcționa:
116
115
117
116
```html
118
117
<scriptsrc="file.js"></script>
@@ -122,11 +121,12 @@ The example above can be split into two scripts to work:
122
121
```
123
122
````
124
123
125
-
## Summary
124
+
## Rezumat
126
125
127
-
- We can use a `<script>` tag to add JavaScript code to a page.
128
-
- The `type` and `language` attributes are not required.
129
-
- A script in an external file can be inserted with `<script src="path/to/script.js"></script>`.
126
+
- Putem folosi un tag `<script>` pentru a adăuga cod JavaScript într-o pagină.
127
+
- Atributele `type` și `language` nu sunt necesare.
128
+
- Un script poate fi inserat într-un fișier extern cu `<script src="path/to/script.js"></script>`.
130
129
131
130
132
-
There is much more to learn about browser scripts and their interaction with the webpage. But let's keep in mind that this part of the tutorial is devoted to the JavaScript language, so we shouldn't distract ourselves with browser-specific implementations of it. We'll be using the browser as a way to run JavaScript, which is very convenient for online reading, but only one of many.
131
+
Există mult mai multe lucruri de învățat despre script-urile browser-ului și interacțiunea lor cu pagina web.
132
+
Dar să reținem că această parte a tutorialului este dedicată limbajului JavaScript, deci nu trebuie să ne distragem cu implementările specifice browserului. Vom folosi browser-ul ca o modalitate de a rula JavaScript, care este foarte convenabil pentru citirea online, dar doar unul dintre mulți.
0 commit comments