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
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
+
Uzmi rješenje prošlog zadatka <info:task/hello-alert>. Izmjeni ga tako što ćeš sadržaj skripte prebaciti u eksternu datoteku`alert.js`, koja se nalazi u istom folderu.
8
8
9
-
Open the page, ensure that the alert works.
9
+
Otvori stranicu, budi siguran da alert radi ispravno.
This part of the tutorial is about core JavaScript, the language itself.
3
+
Ovaj dio tutorijala je o jezgri samog jezika, JavaScript-a.
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
+
Ali nam treba radno okruženje gdje ćemo pokretati naše skripte, i pošto je ova knjiga na internetu, pretraživač je dobar izbor. Nećemo puno koristiti komande specifične za pretraživače (kao što je `alert`) tako da ne provedete puno vremena na njih ako planirate da se koncentrirate na drugo okruženje (kao na primjer Node.js). Fokusirat ćemo se na JavaScript u pretraživaču u [sljedećem dijelu](/ui)tutorijala.
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
+
Prvo, hajmo vidjeti kako povezati skriptu sa web stranicom. Za okruženja sa serverske strane (kao što je Node.js), možete izvršiti skriptu sa ovom komandom`"node my.js"`.
8
8
9
9
10
-
## The "script" tag
10
+
## "script" oznaka (eng. tag)
11
11
12
-
JavaScript programs can be inserted into any part of an HTML document with the help of the `<script>`tag.
12
+
JavaScript programi mogu biti ubačeni u bilo koji dio HTML dokumenta uz pomoć `<script>`oznake.
13
13
14
-
For instance:
14
+
Kao na primjer:
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>Prije skripte...</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>...Poslije skripte.</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
+
Možete pokrenuti ovaj primjer tako što ćete pritisnuti "Play" tipku u gornjem desnom uglu kocke iznad.
39
39
```
40
40
41
-
The `<script>` tag contains JavaScript code which is automatically executed when the browser processes the tag.
41
+
`<script>` tag sadrži JavaScript kod koji se automatski izvršava kada pretraživač procesira tag.
42
42
43
43
44
-
## Modern markup
44
+
## Moderni markup
45
45
46
-
The `<script>` tag has a few attributes that are rarely used nowadays but can still be found in old code:
46
+
The `<script>` tag ima nekoliko atributa koji se rijetko koriste danas ali se i dalje mogu pronaći u starom kodu:
47
47
48
-
The `type`attribute: <code><script <u>type</u>=...></code>
49
-
: 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.
: Stari HTML standard, HTML4, je zahtijevao da skripta ima `type`. Obično je to bilo `type="text/javascript"`. Ovo više nije potrebno. Isto tako, moderni HTML standard totalno je promijenio značenje ovog atributa. Sada, može se koristiti za JavaScript module. Ali to je napredna tema, pričat ćemo o modulima u drugom dijelu tutorijala.
50
50
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.
: Ovaj atribut je trebao predstavljati jezik date skripte. Ovaj atribut više nema smisla za koristiti, jer je JavaScript uobičajeni jezik. Nema razloga da se ovaj atribut više koristi.
53
53
54
-
Comments before and after scripts.
55
-
: In really ancient books and guides, you may find comments inside `<script>`tags, like this:
54
+
Komentari prije i poslije skripta.
55
+
: U veoma starim knjigama i vodičima, možete pronaći komentare unutar `<script>`tag-ova, kao na primjer ovdje:
56
56
57
57
```html no-beautify
58
58
<script type="text/javascript"><!--
59
59
...
60
60
//--></script>
61
61
```
62
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.
63
+
Ovaj trik se ne koristi u modernom JavaScript-u. Ovi komentari kriju JavaScript kod od starih pretraživača koji ne znaju kako da procesiraju `<script>` tag. Pošto pretraživači koji su izašli u zadnjih 15 godina nemaju više ovaj problem, ovaj tip komentara može vam pomoći da identifikujete veoma star kod.
64
64
65
65
66
-
## External scripts
66
+
## Eksterne skripte
67
67
68
-
If we have a lot of JavaScript code, we can put it into a separate file.
68
+
Ako imamo puno JavaScript koda, možemo ga staviti u posebnu datoteku.
69
69
70
-
Script files are attached to HTML with the `src`attribute:
70
+
Skript datoteke su povezane sa HTMLom preko `src`atributa:
71
71
72
72
```html
73
-
<scriptsrc="/path/to/script.js"></script>
73
+
<scriptsrc="/put/do/script.js"></script>
74
74
```
75
75
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"`would mean a file `"script.js"`in the current folder.
76
+
Ovdje, `/put/do/script.js`je apsolutan put do skripte od korijena stranice. Možete pružiti relativni put od trenutne stranice. Na primjer, `src="script.js"`bi značilo `"script.js"`je u trenutnom folderu.
Da bismo povezali više skript datoteka, koristimo više tagova:
85
85
86
86
```html
87
87
<scriptsrc="/js/script1.js"></script>
@@ -90,43 +90,43 @@ To attach several scripts, use multiple tags:
90
90
```
91
91
92
92
```smart
93
-
As a rule, only the simplest scripts are put into HTML. More complex ones reside in separate files.
93
+
Kao pravilo, samo najjednostavnije skripte se postavljaju direktno u HTML. One koje su više kompleksne trebaju biti u eksternim, odvojenim datotekama.
94
94
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).
95
+
Prednost odvojene datoteke jeste to da će je pretraživač preuzeti i spasiti u [keš memoriju](https://en.wikipedia.org/wiki/Web_cache).
96
96
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.
97
+
Ostale stranice koje uzimaju istu skriptu kao referencu uzeti će iz keš memorije umjesto ponovnog preuzimanja, tako da se ta datoteka samo jednom treba preuzeti.
98
98
99
-
That reduces traffic and makes pages faster.
99
+
To smanjuje promet i ubrzava stranicu.
100
100
```
101
101
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.
102
+
````warn header="Ako je `src`postavljen, sadržaj skripte će biti ignorisan."
103
+
Jedan `<script>` tag ne može imati oboje, i `src`atribut i kod iznutra.
104
104
105
-
This won't work:
105
+
Ovo neće raditi:
106
106
107
107
```html
108
-
<script*!*src*/!*="file.js">
109
-
alert(1); //the content is ignored, because src is set
108
+
<script*!*src*/!*="datoteka.js">
109
+
alert(1); //sadržaj je ignorisan, jer je postavljen src
110
110
</script>
111
111
```
112
112
113
-
We must choose either an external `<script src="…">`or a regular `<script>`with code.
113
+
Moramo odabrati ili eksterni `<script src="…">`ili obični `<script>`tag sa kodom.
114
114
115
-
The example above can be split into two scripts to work:
115
+
Primjer iznad može biti podijeljen na dvije skripte kako bi radio:
116
116
117
117
```html
118
-
<scriptsrc="file.js"></script>
118
+
<scriptsrc="datoteka.js"></script>
119
119
<script>
120
120
alert(1);
121
121
</script>
122
122
```
123
123
````
124
124
125
-
## Summary
125
+
## Sažetak
126
126
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>`.
127
+
- Možemo koristiti `<script>` tag da dodamo JavaScript kod na stranicu.
128
+
- `type` i `language` atributi više nisu potrebni.
129
+
- Skripta u eksternoj datoteci može biti dodana sa `<script src="put/do/script.js"></script>`.
130
130
131
131
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.
132
+
Ima još mnogo toga da se nauči o skriptama u pretraživaču kao i o njihovoj interakciji sa web stranicom. Ali moramo imati na umu da je ovaj dio tutorijala posvećen JavaScript jeziku, tako da ne želimo odvratiti pažnju sa implementacijama specifičnim za pretraživače. Koristit ćemo pretraživač kao način da pokrenemo JavaScript, što je veoma pogodno za online čitanje, ali to je samo jedan od načina.
0 commit comments